© ETH Zürich | L – Modeling and Simulating Social Systems with MATLAB Lecture 3 – Dynamical Systems © ETH Zürich | Giovanni Luca Ciampaglia, Stefano Balietti and Karsten Donnay Chair of Sociology, in particular of Modeling and Simulation
G. L. Ciampaglia, S. Balietti & K. Donnay / 2 Projects Implementation of a model from the Social-Science literature in MATLAB Carried out in pairs The projects will be assigned next week: October 18, 2010 Project suggestions are online now; please visit the website and read through the material!
G. L. Ciampaglia, S. Balietti & K. Donnay / 3 Lesson 3 - Contents Differential Equations Dynamical Systems Pendulum Lorenz attractor Lotka-Volterra equations Epidemics: Kermack-McKendrick model Exercises
G. L. Ciampaglia, S. Balietti & K. Donnay / 4 Differential equations Solving differential equations numerically can be done by a number of schemes. The easiest way is by the 1 st order Euler’s Method: t x ΔtΔt x(t) x(t-Δt)
G. L. Ciampaglia, S. Balietti & K. Donnay / 5 Dynamical systems Mathematical description of the time dependence of variables that characterize a given problem/ scenario in its state space A dynamical system is described by a set of linear/non-linear differential equations. Even though an analytical treatment of dynamical systems is usually very complicated, obtaining a numerical solution is (often) straight forward.
G. L. Ciampaglia, S. Balietti & K. Donnay / 6 Pendulum A pendulum is a simple dynamical system: L = length of pendulum (m) = angle of pendulum g = acceleration due to gravity (m/s 2 ) The motion is described by:
G. L. Ciampaglia, S. Balietti & K. Donnay / 7 Pendulum: MATLAB code
G. L. Ciampaglia, S. Balietti & K. Donnay / 8 Set time step
G. L. Ciampaglia, S. Balietti & K. Donnay / 9 Set constants
G. L. Ciampaglia, S. Balietti & K. Donnay / 10 Set starting point of pendulum
G. L. Ciampaglia, S. Balietti & K. Donnay / 11 Time loop: Simulate the pendulum
G. L. Ciampaglia, S. Balietti & K. Donnay / 12 Perform 1 st order Euler’s method
G. L. Ciampaglia, S. Balietti & K. Donnay / 13 Plot pendulum
G. L. Ciampaglia, S. Balietti & K. Donnay / 14 Set limits of window
G. L. Ciampaglia, S. Balietti & K. Donnay / 15 Make a 10 ms pause
G. L. Ciampaglia, S. Balietti & K. Donnay / 16 Pendulum: Executing MATLAB code
G. L. Ciampaglia, S. Balietti & K. Donnay / 17 Lorenz attractor The Lorenz attractor defines a 3-dimensional trajectory by the differential equations: σ, r, b are parameters.
G. L. Ciampaglia, S. Balietti & K. Donnay / 18 Lorenz attractor: MATLAB code
G. L. Ciampaglia, S. Balietti & K. Donnay / 19 Set time step
G. L. Ciampaglia, S. Balietti & K. Donnay / 20 Set number of iterations
G. L. Ciampaglia, S. Balietti & K. Donnay / 21 Set initial values
G. L. Ciampaglia, S. Balietti & K. Donnay / 22 Set parameters
G. L. Ciampaglia, S. Balietti & K. Donnay / 23 Solve the Lorenz-attractor equations
G. L. Ciampaglia, S. Balietti & K. Donnay / 24 Compute gradient
G. L. Ciampaglia, S. Balietti & K. Donnay / 25 Perform 1 st order Euler’s method
G. L. Ciampaglia, S. Balietti & K. Donnay / 26 Update time
G. L. Ciampaglia, S. Balietti & K. Donnay / 27 Plot the results
G. L. Ciampaglia, S. Balietti & K. Donnay / 28 Animation
G. L. Ciampaglia, S. Balietti & K. Donnay / 29
G. L. Ciampaglia, S. Balietti & K. Donnay / Food chain 30
G. L. Ciampaglia, S. Balietti & K. Donnay / 31 Lotka-Volterra equations The Lotka-Volterra equations describe the interaction between two species, prey vs. predators, e.g. rabbits vs. foxes. x: number of prey y: number of predators α, β, γ, δ: parameters
G. L. Ciampaglia, S. Balietti & K. Donnay / 32 Lotka-Volterra equations The Lotka-Volterra equations describe the interaction between two species, prey vs. predators, e.g. rabbits vs. foxes.
G. L. Ciampaglia, S. Balietti & K. Donnay / 33 Lotka-Volterra equations The Lotka-Volterra equations describe the interaction between two species, prey vs. predators, e.g. rabbits vs. foxes.
G. L. Ciampaglia, S. Balietti & K. Donnay / Epidemics 34 Source: Balcan, et al. 2009
G. L. Ciampaglia, S. Balietti & K. Donnay / 35 SIR model A general model for epidemics is the SIR model, which describes the interaction between Susceptible, Infected and Removed (immune) persons, for a given disease.
G. L. Ciampaglia, S. Balietti & K. Donnay / 36 Kermack-McKendrick model Spread of diseases like the plague and cholera? A popular SIR model is the Kermack-McKendrick model. The model assumes: A constant population size. A zero incubation period. The duration of infectivity is as long as the duration of the clinical disease.
G. L. Ciampaglia, S. Balietti & K. Donnay / 37 Kermack-McKendrick model The Kermack-McKendrick model is specified as: S: Susceptible persons I: Infected persons R: Removed (immune) persons β : Infection rate γ : Immunity rate S I R β transmission γ recovery
G. L. Ciampaglia, S. Balietti & K. Donnay / 38 Kermack-McKendrick model The Kermack-McKendrick model is specified as: S: Susceptible persons I: Infected persons R: Removed (immune) persons β : Infection rate γ : Immunity rate
G. L. Ciampaglia, S. Balietti & K. Donnay / 39 Kermack-McKendrick model The Kermack-McKendrick model is specified as: S: Susceptible persons I: Infected persons R: Removed (immune) persons β : Infection rate γ : Immunity rate
G. L. Ciampaglia, S. Balietti & K. Donnay / 40 Exercise 1 Implement and simulate the Kermack- McKendrick model in MATLAB. Use the starting values: S=I=500, R=0, β =0.0001, γ =0.01
G. L. Ciampaglia, S. Balietti & K. Donnay / 41 Exercise 2 A key parameter for the Kermack-McKendrick model is the epidemiological threshold, β S/ γ. Plot the time evolution of the model and investigate the influence of the epidemiological threshold, in particular the cases: 1. β S/ γ < 1 2. β S/ γ > 1 Starting values: S=I=500, R=0, β =0.0001
G. L. Ciampaglia, S. Balietti & K. Donnay / 42 Exercise 3 - optional Implement the Lotka-Volterra model and investigate the influence of the timestep, dt. How small must the timestep be in order for the 1 st order Euler‘s method to give reasonable accuracy? Check in the MATLAB help how the functions ode23, ode45 etc, can be used for solving differential equations.