a)The Crank-Nicolson method for ODEs is very popular when combined with diffusion equations. For a linear ODE u = au it reads un+1 − un Δt = 1 2 (aun + aun+1) . Apply the Crank-Nicolson method in time to the ODE system for a onedimensional diffusion equation. Identify the linear system to be solved.
b) The Backward Euler, Forward Euler, and Crank-Nicolson methods can be given a unified implementation. For a linear ODE u = au this formulation is known as the θ rule: un+1 − un Δt = (1 − θ )aun + θaun+1 . For θ = 0 we recover the Forward Euler method, θ = 1 gives the Backward Euler scheme, and θ = 1/2 corresponds to the Crank-Nicolson method. The approximation error in the θ rule is proportional to Δt, except for θ = 1/2 where it is proportional to Δt2. For θ ≥ 1/2 the method is stable for all Δt. Apply the θ rule to the ODE system for a one-dimensional diffusion equation. Identify the linear system to be solved.
c) Implement the θ rule with aid of the Odespy package. The relevant object name is ThetaRule:
d) Consider the physical application from Sect. 9.2.4. Run this case with the θ rule and θ = 1/2 for the following values of Δt: 0.001, 0.01, 0.05. Report what you see.