-
For the case in b), find through experimentation the largest value of Δt where the exact solution and the numerical solution by Heun’s method cannot be distinguished visually.
a) A second-order Runge-Kutta method, also known has Heun’s method, is derived in Sect. 8.4.5. Make a function ode_Heun(f, U_0, dt, T) (as a counterpart to ode_FE(f, U_0, dt, T) in ode_FE.py) for solving a scalar ODE problem u = f (u, t), u(0) = U0, t ∈ (0, T ], with this method using…
-
Write up the complete model, implement it, and rerun the case from Sect. 8.3.8 with various choices of parameters to illustrate various effects.
1.In the SIRV model with time-dependent vaccination from Sect. 8.3.9, we want to test the effect of an adaptive vaccination campaign where vaccination is offered 2.We consider the SIRV model from Sect. 8.3.8, but now the effect of vaccination is time-limited. After a characteristic period of time, π, the vaccination is no more effective and…
-
Consider the file osc_FE.py implementing the Forward Euler method for the oscillating system model (8.43)–(8.44).
1.Consider the file osc_FE.py implementing the Forward Euler method for the oscillating system model (8.43)–(8.44). The osc_FE.py code is what we often refer to as a flat program, meaning that it is just one main program with no functions. Your task is to refactor the code in osc_FE.py according to the specifications below. Refactoring, means…
-
Add a call to osc_energy in the programs osc_FE.py and osc_EC.py and plot the sum of the kinetic and potential energy.
a) Make a function osc_energy(u, v, omega) for returning the potential and kinetic energy of an oscillating system described by (8.43)–(8.44). The potential energy is taken as 1 2ω2u2 while the kinetic energy is 1 2 v2. (Note that these expressions are not exactly the physical potential and kinetic energy, since these would be 1…
-
Find an expression for the Nn in terms of Nn−1 and formulate an algorithm for computing Nn, n = 1, 2,…,Nt .
1.We consider the ODE problem N (t) = rN(t), N(0) = N0. At some time, tn = nΔt, we can approximate the derivative N (tn) by a backward difference, see Fig. 8.22: N (tn) ≈ N(tn) − N(tn − Δt) Δt = Nn − Nn−1 Δt , which leads to Nn − Nn−1 Δt =…
-
Make plots for comparing the Crank-Nicolson scheme with the Forward and Backward Euler schemes in the same test problem as in Exercise 8.12.
1.It is recommended to do Exercise 8.12 prior to the present one. Here we look at the same population growth model N (t) = rN(t), N(0) = N0. The time derivative N (t) can be approximated by various types of finite differences. Exercise 8.12 considers a backward difference (Fig. 8.22), while Sect. 8.2.2 explained the…
-
Write the code with a test block, so that it gets easy to either import functions from the module, or to run it as a program.
1.A general ODE problem u (t) = f (u, t), u(0) = U0, may be solved numerically by the third order Runge-Kutta method. The computational scheme reads un+1 = un + Δt 6 (k1 + 4k2 + k3) , n = 0, 1,…,Nt − 1, k1 = f (un, tn), k2 = f (un +…
-
Implement the scheme in a function adams_bashforth_2 that takes appropriate parameters, so that it is easy to import and use whenever needed.
1.Differing from the single-step methods presented in this chapter, we have the multistep methods, for example the Adams-Bashforth methods. With the single-step methods, un+1 is computed by use of the solution from the previous time step, i.e. un. In multi-step methods, the computed solutions from several previous time steps, e.g., un, un−1 and un−2 are…
-
Run the program with a Δt corresponding to 20 time steps per period of the oscillations (see Sect. 8.4.3 for how to find such a Δt).
1.Consider (8.43)–(8.44) modeling an oscillating engineering system. This 2×2 ODE system can be solved by the Backward Euler scheme, which is based on discretizing derivatives by collecting information backward in time. More specifically, u (t) is approximated as u (t) ≈ u(t) − u(t − Δt) Δt . A general vector ODE u = f…
-
Derive the computational scheme and show that (contrary to the Forward Euler scheme) you have to solve a nonlinear algebraic equation for each time step when using this scheme.
1.Let y be a scalar function of time t and consider the nonlinear ODE y + y = ty3, t ∈ (0, 4), y(0) = 1 2 . a) Assume you want to solve this ODE numerically by the Backward Euler method. Derive the computational scheme and show that (contrary to the Forward Euler scheme)…