Practice 5

Question 1

Create a 2 by 3 numpy array containing the following data:

\[\begin{split} \begin{bmatrix} 10 & 12 & 13\\ 5 & 6 & 7 \end{bmatrix} \end{split}\]

Use slice notation to create one-dimensional arrays containing:

  1. The first row

  2. The last column

Calculate:

  1. A 3 element array containing the sum of each of the three columns

  2. A 2 element array containing the sum of each of the two rows

Question 2

A particle follows a trajectory given by the following equations between \(t=0\)s and \(t = 10\)s:

\[\begin{split} x = 4\sin(7t)\\ y = 4\cos(6t) \end{split}\]
  1. Use np.arange to create an array t containing 100 evenly spaced time points from 0 to 10.

  2. Calculate arrays x and y containing the x and y co-ordinates

  3. plot the x and y co-ordinates against time on the same graph.

  4. On a separate graph, plot x against y.

Question 3

The logistic equation describes the growth of a population where the growth rate is limited by resources.

\[x_{i+1} = x_i + r(1-x_i/K)x_i\]

\(r\) and \(K\), both greater than zero, are parameters of the model.

Adapt the ‘Population Growth’ code in the notes to simulate the growth of a population undergoing logistic growth. Experiment with different values of \(r\) and \(K\). What do the two parameters represent?