OUTPUT

 

Run for h=0.5:

 

>> nma_euler_midpoint('y*(x^2-1.2)',0.5,0,2,1)

step      x       y(x)   midpoint_rate  end_step_y

1      0.0000    1.0000  -0.7962        0.6019

2      0.5000    0.6019  -0.2926        0.4556

3      1.0000    0.4556    0.1569        0.5340

4      1.5000    0.5340   1.2557        1.1619

5      2.0000    1.1619    1.1619         1.1619

>>


 

For comparison, this is below the heun method for same h.

They look almost the same, but looking closely, the heun method does better approximation to the true solution.

 


 

Run for h=0.25

 

>> nma_euler_midpoint('y*(x^2-1.2)',0.25,0,2,1)

step     x        y(x)   midpoint_rate   end_step_y

1      0.0000    1.0000  -1.0067        0.7483

2      0.2500    0.7483  -0.6800        0.5783

3      0.5000    0.5783  -0.4125        0.4752

4      0.7500    0.4752  -0.1900        0.4277

5      1.0000    0.4277    0.0274        0.4345

6      1.2500    0.4345    0.3137         0.5130

7      1.5000    0.5130    0.8360        0.7220

8      1.7500    0.7220    2.0610        1.2372

9      2.0000    1.2372    1.2372        1.2372

>>

 

At h=0.25, there is very little difference that can be seen between mid-point and heun for same h.

Finally, this is midpoint h=0.25 method compared to Euler for h=0.25 and h=0.5, it is clear midpoint is better than Euler for same h.