5.4. Exercises#

Game of Life#

Exercise 5.6

Use your answer to Exercise 5.5 to create a Python notebook which simulates the Game of Life. The notebook should be well-organised with import statements, functions and executable code clearly separated.

Investigate how the long-term behaviour of the simulation depends on the initial conditions. Can you find initial states that result in the following?

  1. All life eventually dying out

  2. A pattern which eventually stays constant

  3. A pattern which eventually repeats in a cyclic manner

  4. A pattern which grows indefinitely

Use markdown cells to clearly explain your answers.

Diffusion Model#

Exercise 5.7

Adapt your diffusion model code so that it stores the result in a 3d array z. Each slice z[i,:,:] should be an n by n array representing the concentration of the region at timestep i.

N = 20 # number of time steps
n = 10 # size of region
z = np.zeros((N, n, n))

z[0,:,:] = # the inital concentrations

for i in range(N):
    # set z[i,:,:] to the value of the next moving average

Then create line graphs which show the concentration at a point
1. At the centre
2. Near the edge

Over time. What is the long-term average concentration at each point?

Exercise 5.8

Build a more realistic model of 2-dimensional diffusion. Assume that at each timestep a fraction \(d\) of the concentration in each cell leaks into each of the 8 surrounding cells. This happens in both directions, so that the value \(x_{i,j}\) in the next timestep is given by

\[ x_{i,j} - \mathrm{flow~out~of~cell~} i,j + \mathrm{flow~into~cell~} i, j \]
\[=x_{i,j} - 8d \times x_{i,j} + d \times (\mathrm{sum~of~neighbouring~8~cells}). \]

Build a diffusion model based on the above. Experiment with different values of \(d\).