100% Guaranteed Results


18-330 – Exercise 1: Runge–Kutta methods Solved
$ 20.99
Category:

Description

5/5 – (1 vote)

1. Consider a Runge–Kutta method starting at (𝑑𝑛,π‘₯𝑛) that takes an Euler step of length β„Ž/2 to (𝑑𝑛+1/2,π‘₯𝑛+1/2) and then uses the new evaluation at that point to take a complete Euler step from (𝑑𝑛,π‘₯𝑛) of length β„Ž.
Find the order of this method and write down its Butcher tableau. We will refer to it as the β€œmidpoint method”.
2. Define a type RKMethod to represent a general explicit Runge–Kutta method defined by a Butcher tableau as follows:
struct RKMethod{T} c::Vector{T} b::Vector{T} a::Matrix{T} s::Int # number of stages end
Make it into a function by completing the function
function (method::RKMethod)(f, x, t, h) … end
to execute one step of the corresponding Runge–Kutta method with initial condition π‘₯ at time 𝑑 and step size β„Ž. Your code should work for both scalar and vector π‘₯ and a possibly vector-valued function 𝑓 = 𝑓(𝑑,π‘₯)
(Assume that π‘Ž is a lower-triangular matrix, corresponding to an explicit method.)
3. Define RK methods euler, midpoint and RK4 using their respective tableaus.
4. Write a routine integrate with the signature function integrate(method, f, x0, t0, t_final, h) where method is a RK method as defined above and β„Ž is a fixed step size.
Make sure that the final step lands exactly at the final time by taking that final step as a special case. 5. Use each method on the ODE π‘₯Μ‡ = 1.5π‘₯ with π‘₯0 = 2 and integrate from 𝑑 = 0 for a time 𝑑final = 3.
Find the rate of convergence of the numerical solution to the exact solution as β„Ž β†’ 0 for each method. Do they correspond to our analytical expectations?
𝑒̇(𝑑) = exp [𝑑 βˆ’ 𝑒 sin(𝑒)].
Integrate it using RK4 from 𝑑 = 0 to 𝑑 = 5 with a step size β„Ž = 10βˆ’2. Now integrate it with a step size β„Ž = 10βˆ’3.
Plot both solutions π‘₯(𝑑) as a function of 𝑑. What do you observe? What do you think is happening?
Exercise 2: Adaptivity in the Euler method
In this exercise we will invetigate adaptivity in ODE solvers by taking the simplest case: an adaptive Euler method.
1. Consider one step of the Euler method. Write down the local (single-step) error in terms of the step size β„Ž and the unknown constant 𝐢. Call the approximation obtained at the end of the step π‘₯(1).
2. Now consider taking two consecutive Euler steps of size β„Ž/2. Would you expect this to give a better or a worse approximation to the true solution? Write down the total error after taking the two steps, assuming that the constant 𝐢 is the same for both. Call the approximation at the end of this combined step π‘₯(2).
3. Define Ξ”π‘₯ as the difference between the two approximations. Use this to find the step size β„Žβ€² that will give an error per unit time of a given size
πœ–.
4. Use this derivation to write an adaptive Euler integrator adaptive_euler(f, t0, t_final, epsilon) that tries to keep the global error less than πœ–, using an update rule similar to the one we discussed in class. Add a multiplicative factor 0.9 to that rule to make the method behave better.
5. Use it to integrate the same ODE as in exercise 1. Plot the step size taken as a function of time.
6. Now integrate the equation for the van der Pol oscillator:
π‘₯̈ βˆ’ πœ‡(1 βˆ’ π‘₯2)π‘₯Μ‡ + π‘₯ = 0,
with πœ‡ = 5. Use initial conditions π‘₯0 = 0 and π‘₯Μ‡0 = 1.
7. Plot trajectories in (π‘₯,π‘₯)Μ‡ phase space and (separately) the solution π‘₯(𝑑) as a function of 𝑑.
8. Plot the step size as a function of time. What do you observe? How do you interpret this?
Exercise 3: SIR model In this exercise we will study the SIR model of the dynamics of an infectious disease outbreak (β€œepidemic”) in a population.
1. Use e.g. RK4 to solve the SIR equations:
𝑆 = βˆ’π›½π‘† 𝐼̇ (1)
𝐼 = 𝛽𝑆 𝐼 βˆ’ 𝛾𝐼̇ (2)
𝑅 = 𝛾𝐼̇ (3)
Here 𝐼 is the proportion of the population which is infectious. 𝛽 is the rate of contact between susceptible and infectious individuals, and 𝛾 the recovery rate.
Use 𝑆0 = 0.99 and 𝐼0 = 0.01.
2. Make an interactive visualization, varying 𝛽 and 𝛾 in, say, the range 0 to 1.
3. What do you observe? Can you interpret this?
4. By summing the equations we see that 𝑆 + 𝐼 + 𝑅 should be constant (equal to the total population, assuming no births or deaths). For representative parameter values 𝛽 = 0.1 and 𝛾 = 0.05, how well does the numerics conserve this quantity?

Reviews

There are no reviews yet.

Be the first to review “18-330 – Exercise 1: Runge–Kutta methods Solved”

Your email address will not be published. Required fields are marked *

Related products