Homework Assignment 9 -- Turn in on March 17


  1. Review the Euler Method, the modified Euler Method, Heun Method, and the Midpoint Method given in the last homework assignment. The last three methods are also called the 2nd order Runge-Kutta methods. Review also the 4th order Runge-Kutta methods and particularly the one called the standard 4th order Runge-Kutta method.

  2. Here are function programs in MatLab for these methods.
  3. In the following example, we will use these 5 methods to approximate the solution of the initial value problem
        y'=t+y,  y(1)=2, for t in [1,5].
    
    Since we know the true solution is: y(t)=-(t+1)+4et-1, the true error for each method at each tk is also computed. Both approximation y1, y2, y3, ... and error e1, e2, e3, ... where ek = |y(tk)-yk| are plotted. Here are the MatLab commands used for this example and plots (h=0.2) showed on the screen.
        %
        % Solve y'=t+y, y(1)=2, t in [1,5]
        %
        clear
        a=1;
        b=5;
        y0=2;
        h=input('stepsize h = ');
        tv=a:h:b;
        ysol=-(tv+1)+4*exp(tv-1);
        n=length(tv);
        yeuler=eulfun(tv,y0,h,n);
        yheun=heun(tv,y0,h,n);
        ymodeul=modeul(tv,y0,h,n);
        ymidpt=midpt(tv,y0,h,n);
        yrk4=rk4(tv,y0,h,n);
        clf
        subplot(211),plot(tv(1:n),yeuler(1:n),':');
        hold
        plot(tv(1:n),yheun(1:n),'-.');
        plot(tv(1:n),ymodeul(1:n),'--');
        plot(tv(1:n),ymidpt(1:n),'-');
        plot(tv(1:n),yrk4(1:n),':');
        plot(tv(1:n),yrk4(1:n),'o');
        plot(tv(1:n),ysol(1:n),':');
        plot(tv(1:n),ysol(1:n),'*');
        title('One Step Methods: dy/dt=t+y, y(1)=2, t in [1,5]')
        text(1.5,200,'... Euler Method')
        text(1.5,180,'-.- the 2nd order Runge-Kutta Methods')
        text(1.5,160,'.o. the Std 4th order Runge-Kutta Method')
        text(1.5,140,'.x. the solution y(t)')
        hold off
        erreul=abs(ysol(1:n)-yeuler(1:n));
        errheun=abs(ysol(1:n)-yheun(1:n));
        errmode=abs(ysol(1:n)-ymodeul(1:n));
        errmidpt=abs(ysol(1:n)-ymidpt(1:n));
        errrk4=abs(ysol(1:n)-yrk4(1:n));
        subplot(212),plot(tv(1:n),erreul(1:n),':')
        hold
        plot(tv(1:n),errheun(1:n),'-.')
        plot(tv(1:n),errmode(1:n),'--')
        plot(tv(1:n),errmidpt(1:n),'-')
        plot(tv(1:n),errrk4(1:n),':')
        plot(tv(1:n),errrk4(1:n),'o')
        title('Errors for each method: |y(t_k)-y_k|')
        text(1.5,60,'... Euler Method')
        text(1.5,50,'-.- the 2nd order Runge-Kutta Methods')
        text(1.5,40,'.o. the Std 4th order Runge-Kutta Method')
        hold off
    
    The graphs are given at the end of this assignment.

  4. Use the Euler Method, the modified Euler Method, Heun Method, the Midpoint Method, and the standard 4th order Runge-Kutta method to approximate numerically the solutions of the following two initial value problems with given h. Plot the sequences of yk and the true errors if the true solution is known.
  5. Page 462, #6, #7.

  6. Give the formula for yk+1 when the 3rd Taylor polynomial is used to approximate the solution y(t). Then compute y1 for the initial value problem:
        y'=2ty2, y(0)=1, h=0.2.
    
    The true solution is: y(t)=1/(1-t2). Find the true error for y1.
Here are the graphs: