Modelling and Simulating Social Systems with MATLAB Lesson
![Modelling and Simulating Social Systems with MATLAB Lesson 6 – Cellular Automata A. Johansson Modelling and Simulating Social Systems with MATLAB Lesson 6 – Cellular Automata A. Johansson](https://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-1.jpg)
Modelling and Simulating Social Systems with MATLAB Lesson 6 – Cellular Automata A. Johansson & W. Yu © ETH Zürich | 2009 -03 -16
![Lesson 6 - Contents § Cellular Automata § Neighborhood definitions § Models Game of Lesson 6 - Contents § Cellular Automata § Neighborhood definitions § Models Game of](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-2.jpg)
Lesson 6 - Contents § Cellular Automata § Neighborhood definitions § Models Game of Life § Highway Simulation § Disease Spreading, revisited § § Exercises 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 2
![Cellular Automaton (plural: Automata) § A cellular automaton is a rule, defining how the Cellular Automaton (plural: Automata) § A cellular automaton is a rule, defining how the](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-3.jpg)
Cellular Automaton (plural: Automata) § A cellular automaton is a rule, defining how the state of a cell in a grid is updated, depending on the states of its neighbor cells. § They are represented as grids with arbitrary dimension. § Cellular-automata simulations are discrete both in time and space. 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 3
![Cellular Automaton § The grid can have an arbitrary number of dimensions: 1 -dimensional Cellular Automaton § The grid can have an arbitrary number of dimensions: 1 -dimensional](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-4.jpg)
Cellular Automaton § The grid can have an arbitrary number of dimensions: 1 -dimensional cellular automaton 2009 -03 -16 2 -dimensional cellular automaton A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 4
![Moore Neighborhood § The cells are interacting with each neighbor cells, and the neighborhood Moore Neighborhood § The cells are interacting with each neighbor cells, and the neighborhood](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-5.jpg)
Moore Neighborhood § The cells are interacting with each neighbor cells, and the neighborhood can be defined in different ways, e. g. the Moore neighborhood: 1 st order Moore neighborhood 2009 -03 -16 2 nd order Moore neighborhood A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 5
![Von-Neumann Neighborhood § The cells are interacting with each neighbor cells, and the neighborhood Von-Neumann Neighborhood § The cells are interacting with each neighbor cells, and the neighborhood](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-6.jpg)
Von-Neumann Neighborhood § The cells are interacting with each neighbor cells, and the neighborhood can be defined in different ways, e. g. the Von-Neumann neighborhood: 1 st order Von-Neumann neighborhood 2009 -03 -16 2 nd order Von-Neumann neighborhood A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 6
![Game of Life § Ni = Number of 1 st order Moore neighbors to Game of Life § Ni = Number of 1 st order Moore neighbors to](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-7.jpg)
Game of Life § Ni = Number of 1 st order Moore neighbors to cell i that are activated. § For each cell i: Deactivate: If Ni <2 or Ni >3. 2. Activate: if cell i is deactivated and Ni =3 1. www. mathworld. wolfram. com 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 7
![Game of Life § Ni = Number of 1 st order Moore neighbors to Game of Life § Ni = Number of 1 st order Moore neighbors to](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-8.jpg)
Game of Life § Ni = Number of 1 st order Moore neighbors to cell i that are activated. § For each cell i: Deactivate: If Ni <2 or Ni >3. 2. Activate: if cell i is deactivated and Ni =3 1. www. mathworld. wolfram. com 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 8
![Highway simulation § As an example of a 1 -dimensional cellular automaton, we will Highway simulation § As an example of a 1 -dimensional cellular automaton, we will](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-9.jpg)
Highway simulation § As an example of a 1 -dimensional cellular automaton, we will present a highway simulation. For each car at cell i: Stay: If the cell directly to the right is occupied. 2. Move: Otherwise, move one step to the right, with probability p 1. Move to the next cell, with the probability p 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 9
![Highway simulation § We have prepared some files for the highway simulations: § draw_car. Highway simulation § We have prepared some files for the highway simulations: § draw_car.](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-10.jpg)
Highway simulation § We have prepared some files for the highway simulations: § draw_car. m : Draws a car, with the function draw_car(x 0, y 0, w, h) § simulate_cars. m: Runs the simulation, with the function simulate_cars(move. Prob, in. Flow, with. Graphics) 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 10
![Highway simulation § Running the simulation is done like this: simulate_cars(0. 9, 0. 2, Highway simulation § Running the simulation is done like this: simulate_cars(0. 9, 0. 2,](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-11.jpg)
Highway simulation § Running the simulation is done like this: simulate_cars(0. 9, 0. 2, true) 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 11
![Kermack-Mc. Kendrick model § In lesson 4, we introduced the Kermack. Mc. Kendrick model, Kermack-Mc. Kendrick model § In lesson 4, we introduced the Kermack. Mc. Kendrick model,](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-12.jpg)
Kermack-Mc. Kendrick model § In lesson 4, we introduced the Kermack. Mc. Kendrick model, used for simulating disease spreading. § We will now implement the model again, but this time within the cellular-automata framework. 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 12
![Kermack-Mc. Kendrick model § The Kermack-Mc. Kendrick model is specified as: S: Susceptible persons Kermack-Mc. Kendrick model § The Kermack-Mc. Kendrick model is specified as: S: Susceptible persons](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-13.jpg)
Kermack-Mc. Kendrick model § The Kermack-Mc. Kendrick model is specified as: S: Susceptible persons I: Infected persons R: Removed (immune) persons β: Infection rate γ: Immunity rate 2009 -03 -16 S β transmission R γ recovery A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch I 13
![Kermack-Mc. Kendrick model § The Kermack-Mc. Kendrick model is specified as: S: Susceptible persons Kermack-Mc. Kendrick model § The Kermack-Mc. Kendrick model is specified as: S: Susceptible persons](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-14.jpg)
Kermack-Mc. Kendrick model § The Kermack-Mc. Kendrick model is specified as: S: Susceptible persons I: Infected persons R: Removed (immune) persons β: Infection rate γ: Immunity rate 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 14
![Kermack-Mc. Kendrick model § The Kermack-Mc. Kendrick model is specified as: S: Susceptible persons Kermack-Mc. Kendrick model § The Kermack-Mc. Kendrick model is specified as: S: Susceptible persons](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-15.jpg)
Kermack-Mc. Kendrick model § The Kermack-Mc. Kendrick model is specified as: S: Susceptible persons I: Infected persons R: Removed (immune) persons β: Infection rate γ: Immunity rate 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 15
![Kermack-Mc. Kendrick model § The Kermack-Mc. Kendrick model is specified as: S: Susceptible persons Kermack-Mc. Kendrick model § The Kermack-Mc. Kendrick model is specified as: S: Susceptible persons](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-16.jpg)
Kermack-Mc. Kendrick model § The Kermack-Mc. Kendrick model is specified as: S: Susceptible persons I: Infected persons R: Removed (immune) persons β: Infection rate γ: Immunity rate 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 16
![Kermack-Mc. Kendrick model § The Kermack-Mc. Kendrick model is specified as: S: Susceptible persons Kermack-Mc. Kendrick model § The Kermack-Mc. Kendrick model is specified as: S: Susceptible persons](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-17.jpg)
Kermack-Mc. Kendrick model § The Kermack-Mc. Kendrick model is specified as: S: Susceptible persons I: Infected persons R: Removed (immune) persons β: Infection rate γ: Immunity rate 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 17
![Kermack-Mc. Kendrick model § The Kermack-Mc. Kendrick model is specified as: For the MATLAB Kermack-Mc. Kendrick model § The Kermack-Mc. Kendrick model is specified as: For the MATLAB](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-18.jpg)
Kermack-Mc. Kendrick model § The Kermack-Mc. Kendrick model is specified as: For the MATLAB implementation, we need to decode the states {S, I, R}={0, 1, 2} in a matrix x. S S S S 0 0 0 0 I I I S S 1 1 1 0 0 I I S S S 1 1 0 0 0 R I I I S S S 2 1 1 1 0 0 0 I I I S S 1 1 1 0 0 I S S S 1 0 0 0 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 18
![Kermack-Mc. Kendrick model § The Kermack-Mc. Kendrick model is specified as: We now define Kermack-Mc. Kendrick model § The Kermack-Mc. Kendrick model is specified as: We now define](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-19.jpg)
Kermack-Mc. Kendrick model § The Kermack-Mc. Kendrick model is specified as: We now define a 2 -dimensional cellularautomaton, by defining a grid (matrix) x, where each of the cells is in one of the states: 0: Susceptible § 1: Infected § 2: Recovered § 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 19
![Kermack-Mc. Kendrick model § The Kermack-Mc. Kendrick model is specified as: At each time Kermack-Mc. Kendrick model § The Kermack-Mc. Kendrick model is specified as: At each time](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-20.jpg)
Kermack-Mc. Kendrick model § The Kermack-Mc. Kendrick model is specified as: At each time step, the cells can change states according to: § A Susceptible individual can be infected by an Infected neighbor with probability β, i. e. State 0 -> 1, with probability β. § An individual can recover from an infection with probability γ, i. e. State 1 -> 2, with probability γ. 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 20
![Cellular-automaton implementation § Implementation of a 2 -dimensional cellularautomaton model in MATLAB is done Cellular-automaton implementation § Implementation of a 2 -dimensional cellularautomaton model in MATLAB is done](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-21.jpg)
Cellular-automaton implementation § Implementation of a 2 -dimensional cellularautomaton model in MATLAB is done like this: Iterate the time variable, t Iterate over all cells, i=1. . N, j=1. . N Iterate over all neighbors, k=1. . M § The iteration over the cells can be done either sequentially, or randomly. 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 21
![Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu /](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-22.jpg)
Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 22
![Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu /](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-23.jpg)
Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 23
![Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu /](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-24.jpg)
Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 24
![Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu /](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-25.jpg)
Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 25
![Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu /](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-26.jpg)
Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 26
![Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu /](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-27.jpg)
Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 27
![Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu /](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-28.jpg)
Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 28
![Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu /](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-29.jpg)
Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 29
![Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu /](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-30.jpg)
Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 30
![Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu /](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-31.jpg)
Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 31
![Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu /](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-32.jpg)
Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 32
![Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu /](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-33.jpg)
Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 33
![Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu /](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-34.jpg)
Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 34
![Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu /](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-35.jpg)
Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 35
![Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu /](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-36.jpg)
Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 36
![Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu /](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-37.jpg)
Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 37
![Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu /](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-38.jpg)
Cellular-automaton implementation § Sequential update: 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 38
![Cellular-automaton implementation § Random update: 2009 -03 -16 A. Johansson & W. Yu / Cellular-automaton implementation § Random update: 2009 -03 -16 A. Johansson & W. Yu /](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-39.jpg)
Cellular-automaton implementation § Random update: 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 39
![Cellular-automaton implementation § Random update: 2009 -03 -16 A. Johansson & W. Yu / Cellular-automaton implementation § Random update: 2009 -03 -16 A. Johansson & W. Yu /](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-40.jpg)
Cellular-automaton implementation § Random update: 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 40
![Cellular-automaton implementation § Random update: 2009 -03 -16 A. Johansson & W. Yu / Cellular-automaton implementation § Random update: 2009 -03 -16 A. Johansson & W. Yu /](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-41.jpg)
Cellular-automaton implementation § Random update: 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 41
![Cellular-automaton implementation § Random update: 2009 -03 -16 A. Johansson & W. Yu / Cellular-automaton implementation § Random update: 2009 -03 -16 A. Johansson & W. Yu /](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-42.jpg)
Cellular-automaton implementation § Random update: 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 42
![Cellular-automaton implementation § Random update: 2009 -03 -16 A. Johansson & W. Yu / Cellular-automaton implementation § Random update: 2009 -03 -16 A. Johansson & W. Yu /](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-43.jpg)
Cellular-automaton implementation § Random update: 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 43
![Cellular-automaton implementation § Random update: 2009 -03 -16 A. Johansson & W. Yu / Cellular-automaton implementation § Random update: 2009 -03 -16 A. Johansson & W. Yu /](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-44.jpg)
Cellular-automaton implementation § Random update: 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 44
![Cellular-automaton implementation § Random update: 2009 -03 -16 A. Johansson & W. Yu / Cellular-automaton implementation § Random update: 2009 -03 -16 A. Johansson & W. Yu /](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-45.jpg)
Cellular-automaton implementation § Random update: 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 45
![Cellular-automaton implementation § Random update: 2009 -03 -16 A. Johansson & W. Yu / Cellular-automaton implementation § Random update: 2009 -03 -16 A. Johansson & W. Yu /](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-46.jpg)
Cellular-automaton implementation § Random update: 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 46
![Cellular-automaton implementation § Random update: 2009 -03 -16 A. Johansson & W. Yu / Cellular-automaton implementation § Random update: 2009 -03 -16 A. Johansson & W. Yu /](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-47.jpg)
Cellular-automaton implementation § Random update: 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 47
![Boundary conditions § The boundary conditions can be any of the following: § Periodic: Boundary conditions § The boundary conditions can be any of the following: § Periodic:](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-48.jpg)
Boundary conditions § The boundary conditions can be any of the following: § Periodic: The grid is wrapped, so that what crosses a border is reappearing at the other side of the grid. § Fixed: Agents are not influenced by what happens at the other side of a border. 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 48
![Boundary conditions § The boundary conditions can be any of the following: Fixed boundaries Boundary conditions § The boundary conditions can be any of the following: Fixed boundaries](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-49.jpg)
Boundary conditions § The boundary conditions can be any of the following: Fixed boundaries 2009 -03 -16 Periodic boundaries A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 49
![MATLAB implementation of the The Kermack-Mc. Kendrick model 2009 -03 -16 A. Johansson & MATLAB implementation of the The Kermack-Mc. Kendrick model 2009 -03 -16 A. Johansson &](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-50.jpg)
MATLAB implementation of the The Kermack-Mc. Kendrick model 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 50
![Set parameter values MATLAB implementation 2009 -03 -16 A. Johansson & W. Yu / Set parameter values MATLAB implementation 2009 -03 -16 A. Johansson & W. Yu /](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-51.jpg)
Set parameter values MATLAB implementation 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 51
![Define grid, x MATLAB implementation 2009 -03 -16 A. Johansson & W. Yu / Define grid, x MATLAB implementation 2009 -03 -16 A. Johansson & W. Yu /](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-52.jpg)
Define grid, x MATLAB implementation 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 52
![Define neighborhood MATLAB implementation 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. Define neighborhood MATLAB implementation 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz.](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-53.jpg)
Define neighborhood MATLAB implementation 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 53
![Main loop. Iterate the time variable, t MATLAB implementation 2009 -03 -16 A. Johansson Main loop. Iterate the time variable, t MATLAB implementation 2009 -03 -16 A. Johansson](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-54.jpg)
Main loop. Iterate the time variable, t MATLAB implementation 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 54
![Iterate over all cells, i=1. . N, j=1. . N MATLAB implementation 2009 -03 Iterate over all cells, i=1. . N, j=1. . N MATLAB implementation 2009 -03](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-55.jpg)
Iterate over all cells, i=1. . N, j=1. . N MATLAB implementation 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 55
![For each cell i, j: Iterate over the neighbors MATLAB implementation 2009 -03 -16 For each cell i, j: Iterate over the neighbors MATLAB implementation 2009 -03 -16](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-56.jpg)
For each cell i, j: Iterate over the neighbors MATLAB implementation 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 56
![The model, i. e. updating rule goes here. MATLAB implementation 2009 -03 -16 A. The model, i. e. updating rule goes here. MATLAB implementation 2009 -03 -16 A.](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-57.jpg)
The model, i. e. updating rule goes here. MATLAB implementation 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 57
![Breaking execution § When running large computations or animations, the execution can be stopped Breaking execution § When running large computations or animations, the execution can be stopped](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-58.jpg)
Breaking execution § When running large computations or animations, the execution can be stopped by pressing Ctrl+C in the main window: 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 58
![Exercise 1 § Download the files draw_car. m and simulate_cars. m from the course Exercise 1 § Download the files draw_car. m and simulate_cars. m from the course](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-59.jpg)
Exercise 1 § Download the files draw_car. m and simulate_cars. m from the course web page, www. soms. ethz. ch/matlab Investigate how the flow (moving vehicles per time step) depends on the density (occupancy 0%. . 100%) in the simulator. This relation is called the fundamental diagram in transportation engineering. 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 59
![Exercise 2 § Download the file disease_spreading. m which is an implementation of the Exercise 2 § Download the file disease_spreading. m which is an implementation of the](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-60.jpg)
Exercise 2 § Download the file disease_spreading. m which is an implementation of the Kermack. Mc. Kendrick model as a Cellular Automaton. § Plot the relative fractions of the states S, I, R, as a function of time, and see if the curves look the same as for the old implementation. 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 60
![Exercise 2 b § Modify the model in the following ways: Change from the Exercise 2 b § Modify the model in the following ways: Change from the](http://slidetodoc.com/presentation_image/b1a7c6f4fe83286d2f21af3c84c130f0/image-61.jpg)
Exercise 2 b § Modify the model in the following ways: Change from the 1 st order Moore neighborhood to a 2 nd and 3 rd order Moore neighborhood. § Make it possible for Removed individuals to change state back to Susceptible. § 2009 -03 -16 A. Johansson & W. Yu / andersj@ethz. ch yuwen@ethz. ch 61
- Slides: 61