2.8 Matlab 3: RK methods

Matlab 2: Euler’s Method
2.8
34
Matlab 3: RK methods
(i) (a) Assuming that the method is consistent, determine the value of b3 .
In this lab, we’ll extend to code for Euler’s method from
Lab 2 to implement higher-order methods.
2.8.1
Runge-Kutta 2 Methods
y 0 (t) = 2t, t > 0,
determine α3 .
(c) Consider the initial value problem:
yi+1 = yi + h(ak1 + bk2 ),
where k1 = f(ti , yi ) and k2 = f(ti + αh, yi + βhk1 ). In
Section 2.4, we saw that if we pick any b 6= 0, and let
α=
1
,
2b
(2.8.3)
β = α,
then we get a second order method: |En | 6 Kh2 .
If we choose b = 1, we get the so-called Modified or
mid-point Euler Method from Section 2.4.
Adapt the Euler.m script to implement this method,
and complete the table below.
n
(b) Assuming that the method is exact when used
to compute the solution to
y(0) = 0,
The RK2 method is:
a = 1 − b,
Initial Value Problems
En
yn
ρ
2
3.720 4.526 × 10−2
4
3.786 2.108 × 10−2
8
y(0) = 1, y 0 (t) = λy(t).
Using that the solution is y(t) = eλt , write out
a Taylor series for y(ti+1 ) about y(ti ) up to
terms of order h4 (note: use that h = ti+1 −
ti ).
Using that RK3-1 should agree with the Taylor Series expansion up to terms of order h3 ,
determine β21 and β32 .
(ii) Write out the equations for this method in the same
form that RK4 was given in Section 2.5.1.
(iii) Write a Matlab program that implements this method.
Test it for your own choice of a differential equation
for which you know the exact solution.
Now use this program to check the order of convergence of the method. If possible, have it compute
the error for different values of n (e.g., n = 2,
n = 4, n = 8, etc). Then produce a log-log plot of
these n against the corresponding errors.
16
32
64
Explain how one should interpret the slope of this
line, and why.
128
256
512
.................................................
Important: Send a summary of your numerical results, and your code for the Modified method to
[email protected] before the end of the lab.
The following exercise is part of a homework assignment. Come to lectures for more details.
Also, have a look at Exercise 2.8.1.
Exercise 2.8.1. ? Here is the tableau for a three stage
Runge-Kutta method, which we’ll call RK3-1 (because
that is its name).
0
2/3
β21
α3
1/3
β32
1/4
0
b3
(iv) Write a version of the programme that can implement a Runge-Kutta method, up to four stages, for
any tableau. Find an example of an RK2 and RK3
method that were not covered in lectures, and verify
that your program works for these.