2.4. Exercises#
Use a for
loop to produce the following output:
5, 7, 9, 11, 13, 15
1, 10, 100, 1000, 10000, 100000
0, 1, 2, 0, 1, 2, 0, 1, 2
(hint: use the%
operator)
Look up the predicted daily maximum and minimum temperatures for the next 10 days according to the BBC weather forecast.
https://www.bbc.co.uk/weather/2643743
Create two arrays containing the maximum and minimum temperatures and plot them as two separate lines on a line graph, including axis labels and title. Look up how to add a legend in the Matplotlib documentation.
The Belousov–Zhabotinsky reaction, or BZ reaction, is a chemical reaction which exhibits non-equilbrium dynamics. Under certain conditions, the BZ reaction results in oscillatory behaviour, as demonstrated in this video.
The BZ reaction can be modelled by the following equations, where \(X_i\) and \(Y_i\) are the concentrations of the two reactants X (red) and Y (colourless) at timestep \(i\).
where \(k_1=0.2\), \(k_2 = 0.4\), \(k_3 = 0.1\) and \(k_4 = 0.3\). The initial concentrations are zero and each timestep has a duration of one second.
Write code to calculate \(X_i\) and \(Y_i\) for the first \(300\) seconds. (Hint: you can use your answer to Exercise 2.8 as a template).
On on set of axes, plot a graph of \(X\) and \(Y\) against time, an in another on another plot \(Y\) against \(X\). Check that your plots look like the examples below. Notice how both \(X\) and \(Y\) reach a steady-state.
Keeping the other parameters fixed, experiment with different values of \(k_1\) between \(0.1\) and \(0.3\). For what range of values of \(k_1\) does the reaction reach a steady-state, and for which values dos it exhibit sustained oscillations?
Adapt your solution to the cannonball problem to incorporate air resistance. Assume that at each time step the x- and y-velocities each reduce by a fixed fraction \(d\) (so that the velocity equations become \(u_{i+1} = u_i - du_i\) and \(v_{i+1} = v_i - g\Delta t - dv_i\)).
For a given \(d\), what value of \(\theta\) maximises the distance travelled by the cannonball?