The Midpoint Method

Let's consider the initial value problem
dy/dt = t*exp(3*t) - 2*y
y(0) = 0
0 <= t <= 1
A Matlab script to solve this problem that employs the midpoint method can be downloaded here . It uses the functions deriv.m and exact.m to make the program more readable.

Here is what you get with h=0.1 using the Midpoint Method:

prob541a_h=0.1_midpoint.jpeg

Here is what you get with h=0.1 using the Euler's Method:

prob541a_h=0.1_euler.gif

h Exact Result Midpoint Result Euler Result Midpoint Error Euler Error
0.2 3.2190993e+00 3.2345605e+00 2.3106453e+00 1.5461209e-02 9.0845401e-01
0.1 3.2190993e+00 3.2254163e+00 2.7609015e+00 6.3169639e-03 4.5819785e-01
0.05 3.2190993e+00 3.2209628e+00 2.9897243e+00 1.8634692e-03 2.2937507e-01
0.025 3.2190993e+00 3.2190993e+00 4.9960005e-04

Estimate order according to p = log[error(h)/error(h/2)]/log[2]

Euler:
h=0.2/h=0.1: p=0.987
h=0.1/h=0.05: p=0.998

Midpoint:
h=0.2/h=0.1: p=1.291
h=0.1/h=0.05: p=1.761
h=0.05/h=0.025: p=1.900