It is easy to modify your Euler scheme code for a system of (two) ODEs:

y

y

Copy the file with your scalar Euler scheme code to a file with a new name (e.g. Euler2.m), and make the necessary changes.

You can simply rename the single old unknown to y1n, and introduce the 2nd unknown y2n (and y20, and f2),

and a 2nd Euler update for y2. The functions f1 and f2 should be calculated in a FCN subprogram.

Debug your code on the easy problem, for 0 ≤ t ≤ 1:

y

y

This can be solved exactly: Setting z=y

so this system is equivalent to the 2nd order linear ODE

Solve it to show that the unique solution is:

At each time step, output:

and calculate the worst overall error:

Make runs with N=1000 , N=5000 , N=10000 time-steps. Observe how the error decreases.

Submit

from run with N=1000: input , y1(1) , ERRmax

-----------------------------------------------------------

from run with N=5000: input , y1(1) , ERRmax

-----------------------------------------------------------

your code