Satyagopal Mandal
Department of Mathematics
University of Kansas
Office: 624 Snow Hall  Phone: 785-864-5180


  • e-mail: mandal@math.ku.edu
  • © Copy right Laws Apply. My Students have the permission to copy.

    Differential Equations : Improved Euler Method : Matlab Program

    The following is a Matlab program to solve differential equations numerically using Improved Euler's Method . I will explain how to use it at the end:

    The Program:

    function z=z(n,t0,t1,y0)
    h=(t1-t0)/n;
    t(1)=t0;
    z(1)=y0;
    for i=1:n
    t(i+1)=t(i)+h;
    z(i+1)=z(i)+((ex(t(i),z(i))+ex(t(i+1),z(i)+h*ex(t(i),z(i))))*h)/2;
    end;
    IE=[t',z']
    plot(t,z)
    title('satya')

    How to Use the Program?

    1. You have to have the above program in a filename.m-file. I would call it ieuler.m.
    2. You also have to have a file ex.m and you type in your equation in the file. I typed in a problem as follows:
      %x is a function of t and y is the first derivative x'(t)
      function y=y(t,x)
      y=(t^2-x^2)*sin (x);

    3. Now, on matlab prompt, you write ieuler(n,t0,t1,y0) and return , where n is the number of t-values, t0 and t1 are the left and right end points and y(t0)=y0 is the innitial condition.
    4. Matlab will return your answer. You should also get the graph, if your computer is set up properly. I do not get the graph in my office but I get it in the lab.