modeling and simulating social systems with matlab · linear/non-linear differential equations....

Post on 20-Jun-2020

5 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

12-10-2015 © ETH Zürich |

Modeling and Simulating Social Systems with MATLAB

Lecture 4 – Dynamical Systems

© ETH Zürich |

Computational Social Science

Stefano Balietti, Olivia Woolley, and Dirk Helbing

12-10-2015 Modeling and Simulation of Social Systems with MATLAB

Checking variable relationship- recap

2

• Taking logarithm allows to clearly see relationship between dependent and independent variable (easy to see straight line) • Matlab command: plot(x, log(y), ‘m--’, ‘LineWidth’, 2)

Color of line: magenta (m) Style of line: --

Use ‘LineWidth’ to set width of line to 2 in this case

Note the scale change: y∈[e,2.5*10^4] ⇒y’=log(y) ∈[1,10.12]

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 3

Research Plan Structure

Brief, general introduction to the problem (the context)

How you abstract the problem with a model

What type of model are you going to use? (Diff eqs, cellula automata, agent based…)

What rules are you assuming, how do basic elements of your model interact

Fundamental questions you want to try to answer

What are you trying to show?

Why are you modelling the system?

- Understanding effects of certain parameters and initial conditions

- Reproducing relationship seen in data

Existing literature, and previous projects you will base your model on and possible

extensions.

You need to have at least one reference

Research methods you are planning to use

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 4

Project Upload your project proposals by October 19th as

the readme file on github Quickly present in 1 (3 minute) slide your

research project next week (19 October 2015) Please upload your flash slide by October 18th

midnight to the flashtalk folder on github in pdf format Email us the link to your repo

12-10-2015 Modeling and Simulation of Social Systems with MATLAB

Flash Slide One speaker is enough

On the slide have (at least): Topic Research question Methods (how do you intend to model your system) Reference

5

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 6

Dynamical systems

Mathematical description of the time dependence of variables that characterize a given problem/scenario in its state space.

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 7

Dynamical systems A dynamical system is described by a set of

linear/non-linear differential equations.

Even though an analytical solution of dynamical systems can get quickly very complicated, obtaining a numerical solution is (for simple equations) straight forward.

Differential equation and difference equation are two different tools for operating with Dynamical Systems

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 8

Differential Equations A differential equation is a mathematical

relationship for an unknown function (dependent variable) of one or more (independent) variables that relates the values of the function itself and its derivatives of various orders.

Ordinary (ODE) :

Partial (PDE) :

),(),(),( yxf

yyxf

xyxf

=+∂

∂∂

12-10-2015 Modeling and Simulation of Social Systems with MATLAB

Simplest differential equation:

9

0)( ccxxf +=c

dxxdf

=)(

• Describes a constant rate of change • To solve a differential equation we

must always perform an integration

0)0( cf =

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 10

Numerical Solutions for Differential Equations

Solving differential equations numerically can be done by a number of schemes. The easiest way is by the 1st order Euler’s Method:

,..)( )()(

,...)()()(

,...)(

xfttxttx

xft

txttx

xfdtdx

∆+=∆+

=∆

−∆+

=

t

x

Δt

x(t+Δt)

x(t)

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 12

A famous example: Pendulum A pendulum is a simple dynamical system:

L = length of pendulum (m)

ϴ = angle of pendulum

g = acceleration due to gravity (m/s2)

The motion is described by:

)sin(θθLg

−=′′

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 13

Pendulum: MATLAB code

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 14

Set time step

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 15

Set constants

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 16

Set starting point of pendulum

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 17

Time loop: Simulate the pendulum

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 18

Perform 1st order Euler’s method

)]sin()('[)()(

)()()('

)sin()(')('

)sin()(')(')(''

θθθθ

θθθ

θθθ

θθθθ

Lgtttttt

tttttt

Lgtttt

Lg

ttttt

∆−∆+=∆+

∆−∆+

=∆+

∆−=∆+

−=∆

−∆+=

Notice that we are essentially updating θ & θ’ each time step.

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 19

Plot pendulum

Line connnecting point (0,0) to point (cos(θ), sin(θ) )

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 20

Set limits of window

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 21

Make a 10 ms pause

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 22

Pendulum: Executing MATLAB code

The file pendulum.m can be found on the website!

12-10-2015 Modeling and Simulation of Social Systems with MATLAB

Food chain

24

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 25

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

)(

)(

xydtdy

yxdtdx

δγ

βα

−−=

−=

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 26

Lotka-Volterra equations The Lotka-Volterra equations describe the

interaction between two species, prey vs. predators, e.g. rabbits vs. foxes.

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 27

Lorenz equations The Lorenz equations defines a 3-dimensional trajectory by the

differential equations below: A simplified model of convection (movement of molecules in a fluid) in the earth’s

atmosphere used to understand weather (whole books are written analyzing its results)

σ, r, b are parameters of the flow

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 28

Lorenz attractor: MATLAB code

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 29

Set time step

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 30

Set number of iterations

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 31

Set initial values

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 32

Set parameters

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 33

Solve the Lorenz-attractor equations

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 34

Compute gradient

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 35

Perform 1st order Euler’s method

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 36

Update time

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 37

Plot the results

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 38

Animation

The file lorenzattractor.m can be found on the website!

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 39

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 40

Lotka-Volterra equations The Lotka-Volterra equations describe the

interaction between two species, prey vs. predators, e.g. rabbits vs. foxes.

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 41

SIR model A general model for epidemics is the SIR model,

which describes the interaction between Susceptible, Infected and Removed (Recovered) persons, for a given disease.

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 42

Kermack-McKendrick model Spread of diseases like the plague and cholera?

A popular SIR model is the Kermack-McKendrick model.

The model assumes: Constant population size. No incubation period. The duration of infectivity is as long as the duration of

the clinical disease.

12-10-2015 Modeling and Simulation of Social Systems with MATLAB

Kermack-McKendrick model

44

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 45

Kermack-McKendrick model (reaction equations, nonlinear)

The Kermack-McKendrick model is specified as: S: Susceptible I: Infected R: Recovered β: Infection/contact rate γ: Recovery rate )(

)( )()(

)()(

tIdtdR

tItStIdtdI

tStIdtdS

γ

γβ

β

=

−=

−= Note: No one is added to the susceptible group in this case.

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 46

Kermack-McKendrick model The Kermack-McKendrick model is specified as:

S: Susceptible I: Infected R: Removed/recovered β: Contact rate γ: Recovery rate

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 51

Exercise 1 Implement and simulate the Kermack-

McKendrick model in MATLAB. Use the values: S(0)=I(0)=500, R(0)=0, β=0.0001, γ =0.01

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 52

Exercise 2 A key parameter for the Kermack-McKendrick

model is the reproductive number R0= β/γ. Plot the time evolution of the model and investigate the epidemiological threshold, in particular the cases:

1. R0S(0) < 1 2. R0S(0) > 1

S(0)=I(0)=500, R(0)=0, β=0.0001

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 53

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 1st 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.

12-10-2015 Modeling and Simulation of Social Systems with MATLAB 54

References Strogatz, Steven. "Nonlinear dynamics and chaos: with applications

to physics, biology, chemistry and engineering”, 2001.

Chen et al. “A minimal model of predator- swarm interactions”, JRSI, 2014.

Kermack, W.O. and McKendrick, A.G. "A Contribution to the Mathematical Theory of Epidemics." Proc. Roy. Soc. Lond. A 115, 700-721, 1927.

Keeling, Matt J., and Pejman Rohani. "Modeling infectious diseases in humans and animals". Princeton University Press, 2008.

Aoki. “A simulation study on the schooling mechanism in fish.” Bulletin of the Japanese Society of Scientific, 1982.

top related