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 = rNn , called the Backward Euler scheme. a) Find an expression for the Nn in terms of Nn−1 and formulate an algorithm for computing Nn, n = 1, 2,…,Nt . b) Implement the algorithm in a) in a function growth_BE(N_0, dt, T) for solving N
= rN, N(0) = N0, t ∈ (0, T ], with time step Δt (dt). c) Implement the Forward Euler scheme in a function growth_FE(N_0, dt, T) as described in b). d) Compare visually the solution produced by the Forward and Backward Euler schemes with the exact solution when r = 1 and T = 6. Make two plots, one with Δt = 0.5 and one with Δt = 0.05.
#Sales Offer!| Get upto 25% Off: