(a) Implement the Crank-Nicolson method (function y = CrankNicolson(func,t,y1)) defined as ti+1 +ti yi + Yi+1 4+1 = y +
Posted: Thu May 12, 2022 8:14 am
(a) Implement the Crank-Nicolson method (function y = CrankNicolson(func,t,y1)) defined as ti+1 +ti yi + Yi+1 4+1 = y + (ti+1 – t) 2 2 to solve initial value problems of the form y(t) = f(t, y(t)). t. (b) Using the problem y(t) = 10 cos(t) - 2y(t) with y(0) = 1 and 0 <<< 1 solve the ODE using backward Euler, forward Euler, and Crank-Nicolson for different number of time steps n = 24, 25,... 29 and compute the error to the reference solution. The expression error = max(abs(yref-y)); will compute the error max lyrej (ti) – yil 1 if yref is the vector of exact values at points t; and y is the vector of y values computed with one of the methods. Output a table for each of the three methods with three columns each: time step size, corresponding error, and error rate. Note: the exact solution to this ODE is given by: y(t) = -3e-24 + 2 sin(t) + 4 cos(t). Make sure you get the rates we are expecting from the orders as discussed in lecture. Finally, make sure you are not confusing number of time steps n with the number of points ti.