Starting from:

$25

CTA200 -Assignment 2 Solved

Question 1
The numerical approximation of the derivative of a mathematical function f evaluated as x0 can be written as:

 

Where h is some small “step”. This is found by looking at the Taylor series of f(x) and taking h → 0. A better approximation, when h is finite (rather than infinitessimal) is:

 

Make a python function that has the form def deriv(f, x0, h) that takes in a python function, and returns the approximation of the derivative at x0 using stepsize h for each of the methods. Use your functions to take the derivative of the function f(x) = sin(x) for x0 = 0.1 using a variety of values of h < 1. Plot the error compared to the analytical derivative (ie abs(d numerical - d analytic) / d analytic) as a function of h for each method on the same loglog plot. What do you notice? What does the slope represent?

[3] Question 2
For each point in the complex plane c = x+iy, with −2 < x < 2 and −2 < y < 2, set z0 = 0 and iterate the equation zi+1 = zi2 + c. Note what happens to the zi’s: some points will remain bounded in absolute value |z|2 = <(z)2 +=(z)2, while others will run off to infinity. Make an image in which your points c that diverge are given one color and those that stay bounded are given another. Make a second image where the points are coloured by a colourscale that indicates the iteration number at which the given point diverged.

[3] Question 3
The SIR model is a simple mathematical model of disease spread in a population. The model divides a fixed population of size N into three groups, which vary as a function of time, t:

•    S(t) is those that are susceptible but not yet infected • I(t) is the number of infected individuals

1

•    R(t) is those individuals that have recovered and are now immune

The model can be described by a set of 3 first order differential equations for each of the variables as

                                                                                                                                                 (1)

                                                                                                                                           (2)

                                                                                                                                                         (3)

Using the ODE integrator of your choice (must be callable in Python, we recommend using Scipy as will be covered in lecture on Friday), integrate the equations with N = 1000 from t = 0 to t = 200 for various values of γ and β (at least 3-4 values, justify your choices physically).

Use the initial condition I(0) = 1,S(0) = 999,R(0) = 0 (you can also experiment with other initial conditions if you wish). Plot the curves for S,I,R on the same figure with a legend. make separate plots for each choice of the parametersi (hint: use the subplots() command).

Bonus (+0.5 mark): Add a 4th parameter D for deaths and justify the addition of a 4th differential equation as well as any RHS terms that must be changed on the initial 3 equations. Integrate the new set of equations for some choice of parameters and comment on the results compared to the SIR model.

[2] Question 4
To practice using the LaTex, markup language, we would like you to writeup your results in a .tex file and submit both the LaTex code and the associated PDF. For each of the questions, save and insert your figures into a tex file and write a 1 paragraph methods section, which briefly describes what you did as well as a 1 paragraph analysis section which describes what you see in the results.

More products