The Fourth Order Runge Kutta Method

Let's consider again the initial value problem
dy/dt = t*exp(3*t) - 2*y
y(0) = 0
0 <= t <= 2
A Matlab script to solve this problem that employs Euler's method, the midpoint method, and a fourth order Runge Kutta method can be downloaded here . It uses the functions deriv.m and exact.m .

Let's check the results of the 3 different methods for h=0.2.

method_comp1.jpg

Clearly, Midpoint Method and Runge-Kutta method are much better than Euler's method.

Let's zoom in on the last point:

method_comp2.jpg

Now we can see that the Runge Kutta Method performs better than the midpoint method, as expected.

Let's look at some numbers to make this point; we compare the numbers at t=2.0:

h Exact Result Euler Result Midpoint Result RK4 Result Euler Error Midpoint Error RK4 Error
0.2 1.4523510e+02 1.1235584e+02 1.4608271e+02 1.4533231e+02 3.2879261e+01 8.4760818e-01 9.7209396e-02
0.1 1.4523510e+02 1.2872794e+02 1.4552122e+02 1.4524124e+02 1.6507158e+01 2.8611680e-01 6.1465615e-03
0.05 1.4523510e+02 1.3698635e+02 1.4531508e+02 1.4523548e+02 8.2487460e+00 7.9977337e-02 3.8346926e-04

Clearly, the fourth order Runge Kutta Method performs best. Of course, we need 4 function evaluations for the fourth order Runge Kutta, while we need only 2 (1) for the midpoint (Euler) method. Thus, we should compare RK4 with h=0.2 with Midpoint and h=0.1, and Euler with h=0.05. Those cases require the same amount of work. Still, RK4 is much better !!!!