Upload
trinhngoc
View
220
Download
2
Embed Size (px)
Citation preview
Project on ? Runge Kutta method
Nguyen Quan Ba Hong1
Doan Tran Nguyen Tung2
Nguyen An Thinh3
Students at Faculty of Math and Computer Science
Ho Chi Minh University of Science, Vietnam
email. [email protected]
email. [email protected]
blog. http://hongnguyenquanba.wordpress.com 4
October 2, 2016
1Student ID. 14111032Student ID. 14113523Student ID. 14112894Copyright c© 2016 by Nguyen Quan Ba Hong, Student at Ho Chi Minh University
of Science, Vietnam. This document may be copied freely for the purposes of educationand non-commercial research. Visit my site http://hongnguyenquanba.wordpress.
com to get more.
Contents
List of Figures iii
1 Introduction 11.1 Initial Value Problems . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Mesh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.3 General Runge Kutta method . . . . . . . . . . . . . . . . . . . . 21.4 Runge Kutta Order 1 Method . . . . . . . . . . . . . . . . . . . . 3
2 Runge Kutta order 2 method 42.1 Derivation of Runge Kutta Order 2 Method . . . . . . . . . . . . 4
2.1.1 Runge Kutta Order 2 Formula . . . . . . . . . . . . . . . 42.1.2 Taylor Series Expansion Formula . . . . . . . . . . . . . . 52.1.3 Derivation of System of Equations . . . . . . . . . . . . . 52.1.4 Solutions of System of Equations . . . . . . . . . . . . . . 62.1.5 Some Cases . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2 Matlab Implementation . . . . . . . . . . . . . . . . . . . . . . 7
3 Runge Kutta order 3 method 83.1 Derivation of Runge Kutta Order 3 Method . . . . . . . . . . . . 8
3.1.1 Runge Kutta Order 3 Formula . . . . . . . . . . . . . . . 83.1.2 Taylor Series Expansion Formula . . . . . . . . . . . . . . 103.1.3 Derivation of System of Equations . . . . . . . . . . . . . 103.1.4 Solutions of System of Equations . . . . . . . . . . . . . . 113.1.5 Some Cases . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.2 Matlab Implementation . . . . . . . . . . . . . . . . . . . . . . 19
4 Runge Kutta Order 4 Method 204.1 Derivation of Runge Kutta Order 4 Method . . . . . . . . . . . . 20
4.1.1 Runge Kutta Order 4 Formula . . . . . . . . . . . . . . . 204.1.2 Taylor Series Expansion Formula . . . . . . . . . . . . . . 264.1.3 Derivation of System of Equations . . . . . . . . . . . . . 264.1.4 Solutions of System of Equations . . . . . . . . . . . . . . 294.1.5 Some Cases . . . . . . . . . . . . . . . . . . . . . . . . . . 32
4.2 Matlab Implementation . . . . . . . . . . . . . . . . . . . . . . 334.2.1 Curtiss-Hirchfelder Equation . . . . . . . . . . . . . . . . 33
4.2.1.1 Subroutine s.m . . . . . . . . . . . . . . . . . . . 334.2.1.2 Subroutine f.m . . . . . . . . . . . . . . . . . . . 334.2.1.3 Subroutine x.m . . . . . . . . . . . . . . . . . . . 34
i
CONTENTS ii
4.2.1.4 Main Routine RK4 . . . . . . . . . . . . . . . . 344.2.1.5 Results . . . . . . . . . . . . . . . . . . . . . . . 36
4.2.2 Brusselator Equation . . . . . . . . . . . . . . . . . . . . . 374.2.2.1 Subroutine f.m . . . . . . . . . . . . . . . . . . . 374.2.2.2 Subroutine x.m . . . . . . . . . . . . . . . . . . . 384.2.2.3 Main Routine RK4.m . . . . . . . . . . . . . . . 384.2.2.4 Results . . . . . . . . . . . . . . . . . . . . . . . 43
4.2.3 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . 444.2.3.1 Subroutine s2.m . . . . . . . . . . . . . . . . . . 444.2.3.2 Subroutine f2.m . . . . . . . . . . . . . . . . . . 444.2.3.3 Subroutine x2.m . . . . . . . . . . . . . . . . . . 444.2.3.4 Main Routine RK4ex2.m . . . . . . . . . . . . . 444.2.3.5 Results . . . . . . . . . . . . . . . . . . . . . . . 50
List of Figures
4.1 Numerical Solutions. . . . . . . . . . . . . . . . . . . . . . . 364.2 Absolute Errors. . . . . . . . . . . . . . . . . . . . . . . . . . 374.3 Relative Errors. . . . . . . . . . . . . . . . . . . . . . . . . . 384.4 Numerical Solutions. . . . . . . . . . . . . . . . . . . . . . . 434.5 Dependency of y2 with respect to y1. . . . . . . . . . . . . 444.6 Absolute Errors. . . . . . . . . . . . . . . . . . . . . . . . . . 454.7 Relative Errors. . . . . . . . . . . . . . . . . . . . . . . . . . 464.8 Numerical Solutions. . . . . . . . . . . . . . . . . . . . . . . 504.9 Numerical Solutions. . . . . . . . . . . . . . . . . . . . . . . 514.10 Dependency of y2 with respect to y1. . . . . . . . . . . . . 514.11 Absolute Errors. . . . . . . . . . . . . . . . . . . . . . . . . . 524.12 Relative Errors. . . . . . . . . . . . . . . . . . . . . . . . . . 52
iii
Chapter 1
Introduction
1.1 Initial Value Problems
The Runge Kutta methods are an important family of iterative methods for theapproximation of solutions of ODE’s, that were developed around 1900 by theGerman mathematicians Carl Runge (1856-1927) and Martin. W. Kutta (1867-1944). Modern developments are mostly due to John Butcher in the 1960s.
We consider initial value problems expressed in autonomous form. Startingwith the non-autonomous, we assume that f (x, y) is a continuous function withdomain [a, b]× Rn where t ∈ [a, b] and y ∈ Rn.
Consider the initial value problem
dy (t)
dt= f (t, y (t)) (1.1)
y (x0) = y0 (1.2)
where
y (t) = (y1 (t) , y2 (t) , . . . , yn (t))T
(1.3)
f : [a, b]× Rn → Rn (1.4)
We assume that
‖f (t, y1)− f (t, y2)‖L2(Rn) ≤ L‖y1 − y2‖L2(Rn) (1.5)
for all t ∈ [a, b] , y1 ∈ Rn, y2 ∈ Rn.Thus the IVP (1.1) has a unique solution.For convenience, we write (1.1) briefly as
yt = f (1.6)
Most efforts to increases the order of the Runge Kutta methods have beenaccomplished by increasing the number of Taylor’s series terms used and thusthe number of functional evaluations, e.g. Butcher 1987, Gear 1971. The use ofhigher order derivative terms has been proposed for stiff problems, e.g. Rosen-brock 1963, Enright 1974. Our method add higher order derivative terms to theRunge Kutta ki terms (i > 1) to achieve a higher order of accuracy.
We are interested in a numerical approximation of the continuously differ-entiable solution y (t) of the IVP (1.1) over the time interval t ∈ [a, b].
1
CHAPTER 1. INTRODUCTION 2
1.2 Mesh
We subdivide the interval [a, b] into M equal subintervals and select the meshpoints tj
tj = a+ jh, j = 0, 1, . . . ,M (1.7)
where
h =b− aM
(1.8)
is called a step size.
1.3 General Runge Kutta method
The family of explicit Runge Kutta (RK) methods of the mth stage is given by
y(n+1) = y(n) + h
s∑i=1
biki (1.9)
where
ki = f (τi, ηi) , i = 1, 2, . . . , s (1.10)
and
τi = tn + cih (1.11)
ηi = yn + h
i−1∑j=1
aijkj (1.12)
= yn + h
i−1∑j=1
aijf (τj , ηj) (1.13)
We use the notation
fn := f (tn, yn) (1.14)
To specify a particular method, we need to provide the integer s (the numberof stages), and the coefficients ci, i = 2, . . . , s, aij , 1 ≤ j < i ≤ m and bi, i =1, 2, . . . , s.
These data are usually arranged in a so-called Butcher tableau (after JohnC. Butcher)
0c2 a21c3 a31 a32...
......
. . .
cs as1 as2 · · · ass−1b1 b2 · · · bs−1 bs
(1.15)
CHAPTER 1. INTRODUCTION 3
1.4 Runge Kutta Order 1 Method
We consider the Runge Kutta order 1 method here because it is very short andeasy. There is no need to represent this into a separated chapter.
For s = 1, (1.10) becomes
k1 = f (tn, xn) (1.16)
and (1.10) becomes
y(n+1) = y(n) + hb1k1 (1.17)
= y(n) + hb1fn (1.18)
On the other hand, the Taylor expansion yields
y(n+1) = y(n) + hyt|tn +O(h2)
(1.19)
= y(n) + hfn +O(h2)
(1.20)
Comparing (1.18) and (1.20), we obtain easily
b1 = 1 (1.21)
Hence, The Butcher table in this case has the following form
01
(1.22)
Remark 1.1. The Runge Kutta order 1 method is equivalent to the explicitEuler’s method. Note that the Euler’s method is of the first order of accuracy.Hence, we get the name Runge Kutta method of the ‘first order’ as above.
Chapter 2
Runge Kutta order 2method
2.1 Derivation of Runge Kutta Order 2 Method
To set up the Runge Kutta order 2 method, we need to do 4 steps.
1. Write down Runge Kutta order 2 formula described by (1.9) and (1.10).
2. Write down Taylor series expansion.
3. Compare the coefficients of two formulas above to obtain a system ofequations.
4. Solve the system of equation or find some its solutions.
Remark 2.1. This process is also applied for Runge Kutta method of higherorders. Therefore, we can regard it as the standard process for derivation of thegeneral Runge Kutta method in this context.
After these steps, with some solutions of the derived system of equations,we can simulate some IVPs easily.
2.1.1 Runge Kutta Order 2 Formula
For s = 2, (1.10) becomes
k1 = fn (2.1)
k2 = f (tn + c2h, yn + ha21fn) (2.2)
and (1.9) becomes
y(n+1) = y(n) + hb1k1 + hb2k2 (2.3)
= y(n) + hb1fn + hb2f (tn + c2h, yn + ha21fn) (2.4)
Now we write down the Taylor series expansion O(h2)
for k2
k2 = f (tn + c2h, yn + ha21fn) (2.5)
= fn + c2hft + ha21fnfy +O(h2)
(2.6)
4
CHAPTER 2. RUNGE KUTTA ORDER 2 METHOD 5
Inserting (2.6) into (2.4), we obtain
y(n+1) = y(n) + hb1fn + hb2[fn + c2hft + ha21fnfy +O
(h2)]
(2.7)
= y(n) + h (b1 + b2) fn + h2b2c2ft + h2b2a21fnfy +O(h3)
(2.8)
2.1.2 Taylor Series Expansion Formula
We need to compute ytt for Taylor series expansion below.
ytt =df
dt(2.9)
=∂f
∂t
∂t
∂t+∂f
∂y
∂y
∂t(2.10)
= ft + ffy (2.11)
Now we write down the Taylor series expansion of y in the neighborhood oftn with O
(h3).
y(n+1) = y(n) + hyt|tn +h2
2ytt|tn +O
(h3)
(2.12)
= y(n) + hfn +h2
2ytt|tn +O
(h3)
(2.13)
= y(n) + hfn +h2
2(ft + ffy)|tn +O
(h3)
(2.14)
= y(n) + hfn +h2
2ft
∣∣∣∣tn
+h2
2fn fy|tn +O
(h3)
(2.15)
Remark 2.2. (Important) From here to later, if nothing is misundertood,we can abbreviate notation ftαyβ for
ftαyβ∣∣tn
(2.16)
in the Taylor series expansion.For example, under this abbreviation, (2.15) can be rewritten briefly as
y(n+1) = y(n) + hfn +h2
2ft +
h2
2fnfy +O
(h3)
(2.17)
This abbreviation reduces the complexity of the formulas in this context. Asyou will see later, this abbreviation is really essential.
2.1.3 Derivation of System of Equations
Return to our problem, as usual, comparing (2.8) and (2.17), we obtain
hfn : 1 = b1 + b2 (2.18)
h2ft :1
2= b2c2 (2.19)
h2fnfy :1
2= b2a21 (2.20)
CHAPTER 2. RUNGE KUTTA ORDER 2 METHOD 6
Hence, we obtain the system of equations
b1 + b2 = 1 (2.21)
b2c2 =1
2(2.22)
b2a21 =1
2(2.23)
2.1.4 Solutions of System of Equations
We can solve the above system of equations easily. Here, the authors representtwo solutions. The idea behind these two solutions will be use later for higherorder Runge Kutta method.
Solution 1. The system involves four unknowns in three equations. Tak-ing b2 = α is free variable. Due to (2.23) we must have α 6= 0. Then we caneasily obtain the general solution for (2.21)-(2.23) is
b2 = α (2.24)
b1 = 1− α (2.25)
c2 = a21 =1
2α(2.26)
where α is an arbitrary real number.Butcher tableau in this case becomes
012α
12α
1− α α(2.27)
�
Solution 2. Due to (2.21) and (2.22), we must have c2 = a21. So, we cantake
c2 = a21 = β (2.28)
as a free variable. And the remaining is very easy, we obtain
b1 = 1− 1
2β(2.29)
b2 =1
2β(2.30)
c2 = a21 = β (2.31)
Butcher tableau in this case becomes
0β β
1− 12β
12β
(2.32)
This Butcher tableau appears in [5]. �
Remark 2.3. Since Runge Kutta order 2 is still simple, you can not see thedifferences between two solutions. With Runge Kutta of higher order, you willsee that the first choice of free variables is very important in entire solution.
CHAPTER 2. RUNGE KUTTA ORDER 2 METHOD 7
2.1.5 Some Cases
We discuss two useful choices
Case α =1
2. In this case, (2.26) becomes
b2 =1
2(2.33)
b1 =1
2(2.34)
c2 = a21 = 1 (2.35)
The corresponding Butchet tableau reads
01 1
1
2
1
2
(2.36)
Thus, in this case the Runge Kutta method of second order takes the form
y(n+1) = y(n) +h
2[fn + f (tn + h, yn + hfn)] (2.37)
and is equivalent to the Heun’s method.
Case α = 1. In this case, (2.26) becomes
b2 = 1 (2.38)
b1 = 0 (2.39)
c2 = a21 =1
2(2.40)
The corresponding Butcher tableau reads
01
2
1
20 1
(2.41)
In this case Runge Kutta method of second order can be written as
y(n+1) = y(n) + hf
(tn +
h
2, yn +
h
2fn
)(2.42)
and is called the RK2 method.
Remember α ∈ R∗, so there is infinite many choices of solution for (2.21)-(2.23).
2.2 Matlab Implementation
See section 4.2 for general code.
Chapter 3
Runge Kutta order 3method
3.1 Derivation of Runge Kutta Order 3 Method
3.1.1 Runge Kutta Order 3 Formula
For s = 3, (1.10) becomes
k1 = fn (3.1)
k2 = f (tn + c2h, yn + ha21fn) (3.2)
k3 = f (tn + c3h, yn + ha31k1 + ha32k2) (3.3)
= f (tn + c3h, yn + ha31fn + ha32f (tn + c2h, yn + ha31k1 + ha32k2)) (3.4)
and (1.9) becomes
y(n+1) = y(n) + hb1k1 + hb2k2 + hb3k3 (3.5)
Now we write down the Taylor series expansion O(h3)
for k2.
k2 = f (tn + c2h, yn + ha21fn) (3.6)
= fn + c2hft + ha21fnfy + h2c222ftt + h2c2a21fnfty + h2
a2212f2nfyy (3.7)
+O(h3)
(3.8)
And we also write down the Taylor series expansion O(h3)
for k3.
k3 = f (tn + c3h, yn + ha31fn + ha32k2) (3.9)
= fn + c3hft + h (a31fn + a32k2) fy (3.10)
+ h2c232ftt + c3h
2 (a31fn + a32k2) fty + h2(a31fn + a32k2)
2
2fyy (3.11)
+O(h3)
(3.12)
8
CHAPTER 3. RUNGE KUTTA ORDER 3 METHOD 9
Inserting (3.8) into (3.12)
k3 = f (tn + c3h, yn + ha31fn + ha32k2) (3.13)
= fn + c3hft + ha31fnfy (3.14)
+ ha32fy (fn + hc2ft + ha21fnfy) (3.15)
+ h2c232ftt + c3h
2 (a31fn + a32fn) fty (3.16)
+ h2(a231f
2n + a232f
2n + 2a31a32f
2n
)2
fyy (3.17)
+O(h3)
(3.18)
Collecting terms respect to exponents of h
k3 = fn + h (c3ft + a31fnfy + a32fyfn) (3.19)
+ h2
a32c2ftfy + a21a32fnf
2y +
c232ftt
+c3a31fnfty + c3a32fnfty +a2312f2nfyy
+a2322f2nfyy + a31a32f
2nfyy
(3.20)
+O(h3)
(3.21)
Inserting (3.12) and (3.21) into (3.5)
y(n+1) = y(n) + hb1fn (3.22)
+ hb2
fn + hc2ft + ha21fnfy + h2c222ftt
+h2c2a21fnfty + h2a2212f2nfyy
(3.23)
+ hb3
fn + h (c3ft + a31fnfy + a32fyfn)
+h2
a32c2ftfy + a21a32fnf
2y +
c232ftt
+c3a31fnfty + c3a32fnfty +a2312f2nfyy
+a2322f2nfyy + a31a32f
2nfyy
(3.24)
+O(h4)
(3.25)
Collecting terms respect to exponents of h
y(n+1) = y(n) + h (b1fn + b2fn + b3fn) (3.26)
+ h2 (b2c2ft + a21b2fnfy + b3c3ft + a31b3fnfy + a32b3fyfn) (3.27)
+ h3
b2c22
2ftt + a21b2c2fnfty +
a221b22
f2nfyy
+a32b3c2ftfy + a21a32b3fnf2y +
b3c23
2ftt
+a31b3c3fnfty + a32b3c3fnfty +a231b3
2f2nfyy
+a232b3
2f2nfyy + a31a32b3f
2nfyy
(3.28)
+O(h4)
(3.29)
CHAPTER 3. RUNGE KUTTA ORDER 3 METHOD 10
3.1.2 Taylor Series Expansion Formula
We need to compute yttt for Taylor series expansion below.
yttt =d
dt(ft + ffy) (3.30)
= (ft + ffy)t + f(ft + ffy)y (3.31)
= ftt + ftfy + ffty + ffty + ff2y + f2fyy (3.32)
= ftt + ftfy + 2ffty + ff2y + f2fyy (3.33)
Now we write down the Taylor series expansion of y in the neighborhood oftn with O
(h4).
y(n+1) = y(n) + hyt +h2
2ytt +
h3
6yttt +O
(h4)
(3.34)
= y(n) + hfn +h2
2(ft + fnfy) (3.35)
+h3
6
(ftt + ftfy + 2fnfty + fnf
2y + f2nfyy
)+O
(h4)
(3.36)
3.1.3 Derivation of System of Equations
Comparing (3.29) and (3.36)
hfn : 1 = b1 + b2 + b3 (3.37)
h2ft :1
2= b2c2 + b3c3 (3.38)
h2fnfy :1
2= a21b2 + a31b3 + a32b3 (3.39)
h3ftt :1
6=b2c
22
2+b3c
23
2(3.40)
h3ftfy :1
6= a32b3c2 (3.41)
h3fnfty :1
3= a21b2c2 + a31b3c3 + a32b3c3 (3.42)
h3fnf2y :
1
6= a21a32b3 (3.43)
h3f2nfyy :1
6=a221b2
2+a231b3
2+a232b3
2+ a31a32b3 (3.44)
CHAPTER 3. RUNGE KUTTA ORDER 3 METHOD 11
Hence, we obtain the system of 8 equations with 8 unknowns.
b1 + b2 + b3 = 1 (3.45)
b2c2 + b3c3 =1
2(3.46)
b2a21 + b3 (a31 + a32) =1
2(3.47)
b2c22 + b3c
23 =
1
3(3.48)
b3a32c2 =1
6(3.49)
b2c2a21 + b3c3 (a31 + a32) =1
3(3.50)
b3a32a21 =1
6(3.51)
b2a221 + b3(a31 + a32)
2=
1
3(3.52)
3.1.4 Solutions of System of Equations
We now solve the above system of equations in two different ways.
Solution 1. We take b2 = α, b3 = β as two free variables, then
b1 = 1− α− β (3.53)
our task remains to solve
αc2 + βc3 =1
2(3.54)
αa21 + β (a31 + a32) =1
2(3.55)
αc22 + βc23 =1
3(3.56)
βa32c2 =1
6(3.57)
αc2a21 + βc3 (a31 + a32) =1
3(3.58)
βa32a21 =1
6(3.59)
αa221 + β(a31 + a32)2
=1
3(3.60)
We can solve c2 and c3 by using two equations
αc2 + βc3 =1
2(3.61)
αc22 + βc23 =1
3(3.62)
Since (3.59), we must have β 6= 0.
CHAPTER 3. RUNGE KUTTA ORDER 3 METHOD 12
Then we can take c3 =1
2β− αβc2 from (3.61) and insert into (3.62) to obtain
the following equation respect to c2.
12α (α+ β) c22 − 12αc2 + 3− 4β = 0 (3.63)
Consider two following cases.
1. Case α (α+ β) = 0. Consider two subcases.
(a) Case α = 0. Then we have immediately
β =3
4(3.64)
c3 =2
3(3.65)
b1 =1
4(3.66)
and the system of equations remains
a31 + a32 =2
3(3.67)
a32c2 =2
9(3.68)
3
4a32a21 =
1
6(3.69)
To solve this remaining system of equations, we can take a32 = γ 6= 0as a free variable. Then
a31 =2
3− γ (3.70)
c2 =2
9γ(3.71)
a21 =2
9γ(3.72)
Hence, we obtain the solutions
b1 =1
4(3.73)
b2 = 0 (3.74)
b3 =3
4(3.75)
c2 =2
9γ(3.76)
c3 =2
3(3.77)
a21 =2
9γ(3.78)
a31 =2
3− γ (3.79)
a32 = γ (3.80)
CHAPTER 3. RUNGE KUTTA ORDER 3 METHOD 13
where γ is an arbitrary nonzero real number, in this subcase.
Butcher tableau becomes
02
9γ
2
9γ2
3
2
3− γ γ
1
40
3
4
(3.81)
(b) Case α+ β = 0, α 6= 0. Then we have immediately
b1 = 1 (3.82)
b2 = α (3.83)
b3 = −α (3.84)
c2 =1
3+
1
4α(3.85)
and the system of equations remains
c2 − c3 =1
2α(3.86)
a21 − (a31 + a32) =1
2α(3.87)
c22 − c23 =1
3α(3.88)
a32c2 = − 1
6α(3.89)
c2a21 − c3 (a31 + a32) =1
3α(3.90)
a32a21 = − 1
6α(3.91)
a221 − (a31 + a32)2
=1
3α(3.92)
We again have immediately
c3 =1
3− 1
4α(3.93)
a32 = − 2
4α+ 3(3.94)
a21 =1
3+
1
4α(3.95)
a31 =16α2 + 24α− 9
12α (4α+ 3)(3.96)
CHAPTER 3. RUNGE KUTTA ORDER 3 METHOD 14
Hence, we obtain the solution
b1 = 1 (3.97)
b2 = α (3.98)
b3 = −α (3.99)
c2 =1
3+
1
4α(3.100)
c3 =1
3− 1
4α(3.101)
a21 =1
3+
1
4α(3.102)
a31 =16α2 + 24α− 9
12α (4α+ 3)(3.103)
a32 = − 2
4α+ 3(3.104)
where α is an arbitrary nonzero real number, in this subcase.
Butcher tableau becomes
01
3+
1
4α
1
3+
1
4α1
3− 1
4α
16α2 + 24α− 9
12α (4α+ 3)− 2
4α+ 31 α −α
(3.105)
2. Case α (α+ β) 6= 0. (3.63) is a quadratic equation respect to c2.
Computing the determinant of (3.63)
∆′ = 36α2 + 12α (α+ β) (4β − 3) (3.106)
= 12αβ (4α+ 4β − 3) (3.107)
Hence, we have to make the assumption
αβ (4α+ 4β − 3) ≥ 0 (3.108)
so that (3.63) has roots in this case.
Under this assumption, (3.63) have two roots
c2 =3α±
√3αβ (4α+ 4β − 3)
6α (α+ β)(3.109)
Consider two subcases respect to c2.
(a) Case c2 =3α+
√3αβ (4α+ 4β − 3)
6α (α+ β). We easily solve the remaining
CHAPTER 3. RUNGE KUTTA ORDER 3 METHOD 15
system of equations to get
b1 = 1− α− β (3.110)
b2 = α (3.111)
b3 = β (3.112)
c2 =3α+
√3αβ (4α+ 4β − 3)
6α (α+ β)(3.113)
c3 =3β −
√3αβ (4α+ 4β − 3)
6β (α+ β)(3.114)
a21 =3α+
√3αβ (4α+ 4β − 3)
6α (α+ β)(3.115)
a31 =1
2β−
3α+√
3αβ (4α+ 4β − 3)
6β (α+ β)(3.116)
− α (α+ β)
β(
3α+√
3αβ (4α+ 4β − 3)) (3.117)
a32 =α (α+ β)
β(
3α+√
3αβ (4α+ 4β − 3)) (3.118)
Butcher tableau reads all obtained coefficients.
(b) Case c2 =3α−
√3αβ (4α+ 4β − 3)
6α (α+ β). We also easily solve the re-
maining system of equations to get
b1 = 1− α− β (3.119)
b2 = α (3.120)
b3 = β (3.121)
c2 =3α−
√3αβ (4α+ 4β − 3)
6α (α+ β)(3.122)
c3 =3β +
√3αβ (4α+ 4β − 3)
6β (α+ β)(3.123)
a21 =3α−
√3αβ (4α+ 4β − 3)
6α (α+ β)(3.124)
a31 =1
2β−
3α−√
3αβ (4α+ 4β − 3)
6β (α+ β)(3.125)
− α (α+ β)
β(
3α−√
3αβ (4α+ 4β − 3)) (3.126)
a32 =α (α+ β)
β(
3α−√
3αβ (4α+ 4β − 3)) (3.127)
Butcher tableau reads all obtained coefficients.
We have solved the system of equations (3.45)-(3.52) completely. �
CHAPTER 3. RUNGE KUTTA ORDER 3 METHOD 16
Remark 3.1. In the first solution, we have used b2 and b3 as two free vari-ables. This choice makes square roots appear in the solutions. This is quiteeasy to understand. Because of choice of b2, b3 as free variables, we have tosolve a quadratic equation. This quadratic equation make square roots appearobviously.
Now, we solve our system of equation by alternative ways. The idea is verysimple. It is just a matter of the first choice. More explicitly, instead of choosingb2, b3 as two free variables, we will choose c2, c3 as two free variables. Let us seethe differences between two solutions through the following second one.
Solution 2. We take c2 = α, c3 = β as two free variables and focus onthe following two equations of our system of equations.
b2c2 + b3c3 =1
2(3.128)
b2c22 + b3c
33 =
1
3(3.129)
We consider two cases respect to c2 and c3.
1. Case c2 = c3 = α. Due to (3.57), we must have α 6= 0. Then the abovesub-system of equations becomes
b2 + b3 =1
2α(3.130)
b2 + b3 =1
3α2(3.131)
Hence
c2 = c3 = α =2
3(3.132)
The remaining system of equations is
b1 + b2 + b3 = 1 (3.133)
b2 + b3 =3
4(3.134)
b2a21 + b3 (a31 + a32) =1
2(3.135)
b3a32 =1
4(3.136)
b3a32a21 =1
6(3.137)
b2a221 + b3(a31 + a32)
2=
1
3(3.138)
We obtain immediately
b1 =1
4(3.139)
a21 =2
3(3.140)
CHAPTER 3. RUNGE KUTTA ORDER 3 METHOD 17
and the remaining system of equations is
b2 + b3 =3
4(3.141)
2
3b2 + b3 (a31 + a32) =
1
2(3.142)
b3a32 =1
4(3.143)
4
9b2 + b3(a31 + a32)
2=
1
3(3.144)
We now choose b3 = γ then
b2 =3
4− γ (3.145)
a31 =2
3− 1
4γ(3.146)
a32 =1
4γ(3.147)
Therefore,
c2 =2
3(3.148)
c3 =2
3(3.149)
b1 =1
4(3.150)
b2 =3
4− γ (3.151)
b3 = γ (3.152)
a21 =2
3(3.153)
a31 =2
3− 1
4γ(3.154)
a32 =1
4γ(3.155)
where γ is an arbitrary nonzero real number, is the solution of (3.45)-(3.52)in this case.
2. Case c2 6= c3. Due to (3.49) and (3.51), we have immediately
a21 = c2 = α (3.156)
Due to (3.128) and (3.129), we obtain
b2 =3β − 2
6α (β − α)(3.157)
b3 =3α− 2
6β (α− β)(3.158)
CHAPTER 3. RUNGE KUTTA ORDER 3 METHOD 18
Hence,
b1 =6αβ − 3α− 3β + 2
6αβ(3.159)
The remaining system of equations is
3β − 2
6α (β − α)α+
3α− 2
6β (α− β)(a31 + a32) =
1
2(3.160)
3α− 2
6β (α− β)a32α =
1
6(3.161)
3β − 2
6 (β − α)α+
3α− 2
6 (α− β)(a31 + a32) =
1
3(3.162)
3β − 2
6α (β − α)α2 +
3α− 2
6β (α− β)(a31 + a32)
2=
1
3(3.163)
We easily solve this and obtain
a21 = α (3.164)
a31 = β − β (α− β)
α (3α− 2)(3.165)
a32 =β (α− β)
α (3α− 2)(3.166)
Therefore,
c2 = α (3.167)
c3 = β (3.168)
b1 =6αβ − 3α− 3β + 2
6αβ(3.169)
b2 =3β − 2
6α (β − α)(3.170)
b3 =3α− 2
6β (α− β)(3.171)
a21 = α (3.172)
a31 = β − β (α− β)
α (3α− 2)(3.173)
a32 =β (α− β)
α (3α− 2)(3.174)
where α 6= β, α 6= 2
3are two arbitrary nonzero real numbers, is the solution
of (3.45)-(3.52) in this case.
We have solved (3.45)-(3.52) completely. �
Remark 3.2. In the second solution,nth roots do not appear in the solu-tion because we does not need to solve any polynomial equations. Since thisway is more easy and effective, it will be used for Runge Kutta method of higherorders.
CHAPTER 3. RUNGE KUTTA ORDER 3 METHOD 19
3.1.5 Some Cases
We consider some cases of Runge Kutta order 3 method respect to some solu-tions of its associated system of equations.
Case α =2
3, β =
1
6.
We use case 2.(b) above to obtain
01
2
1
21 −1 2
1
6
2
3
1
6
(3.175)
This Butcher tableau appears in [6] - Kutta’s third order method and in [4], p.82.
Case α =3
8, β =
3
8.
02
3
2
32
30
2
31
4
3
8
3
8
(3.176)
This Butcher tableau appears in [4], p.82.
Case α =3
4, β =
1
4.
02
3
2
30 −1 1
03
4
1
4
(3.177)
This Butcher tableau appears in [4], p.82.
3.2 Matlab Implementation
See section 4.2 for general code.
Chapter 4
Runge Kutta Order 4Method
4.1 Derivation of Runge Kutta Order 4 Method
4.1.1 Runge Kutta Order 4 Formula
For s = 4, (1.10) becomes
k1 = fn (4.1)
k2 = f (tn + c2h, yn + ha21fn) (4.2)
k3 = f (tn + c3h, yn + ha31fn + ha32k2) (4.3)
k4 = f (tn + c4h, yn + ha41fn + ha42k2 + ha43k3) (4.4)
and (1.9) becomes
y(n+1) = y(n) + hb1k1 + hb2k2 + hb3k3 + hb4k4 (4.5)
Now we write down the Taylor series expansion O(h4)
for k2.
k2 = f (tn + c2h, yn + ha21fn) (4.6)
= fn + hc2ft + ha21fnfy + h2c222ftt + h2a21c2fnfty + h2
a2212f2n (4.7)
+ h3c326fttt + h3
a21c22
2fnftty + h3
a221c22
f2nftyy + h3a3216f3nfyyy +O
(h4)(4.8)
= fn + h (c2ft + a21fnfy) + h2(c222ftt + a21c2fnfty +
a2212f2n
)(4.9)
+ h3(c326fttt +
a21c22
2fnftty +
a221c22
f2nftyy +a3216f3nfyyy
)+O
(h4)
(4.10)
20
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 21
We write down the Taylor series expansion O(h4)
for k3.
k3 = f (tn + c3h, yn + ha31fn + ha32k2) (4.11)
= fn + hc3ft + h (a31fn + a32k2) fy (4.12)
+ h2c232ftt + h2c3 (a31fn + a32k2) fty +
1
2h2(a31fn + a32k2)
2fyy (4.13)
+c33h
3
6fttt +
h3c232
(a31fn + a32k2) ftty +h3c3
2(a31fn + a32k2)
2ftyy (4.14)
+h3
6(a31fn + a32k2)
3fyyy +O
(h4)
(4.15)
Inserting (4.10) into (4.15)
k3 = fn + hc3ft + ha31fnfy (4.16)
+ ha32fy
[fn + h (c2ft + a21fnfy) + h2
(c222ftt + a21c2fnfty +
a2212f2n
)](4.17)
+h2c23
2ftt + h2c3a31fnfty + h2c3a32fty [fn + h (c2ft + a21fnfy)] (4.18)
+h2
2a231f
2nfyy +
h2
22a31a32fnfyy [fn + h (c2ft + a21fnfy)] (4.19)
+h2
2a232fyy[fn + h (c2ft + a21fnfy)]
2(4.20)
+c33h
3
6fttt +
h3c232
(a31fn + a32fn) ftty (4.21)
+h3c3
2
(a231f
2n + 2a31a32f
2n + a232f
2n
)ftyy (4.22)
+h3
6
(a331f
3n + 3a231a32f
3n + 3a31a
232f
3n + a332f
3n
)fyyy +O
(h4)
(4.23)
Collecting terms respect to exponents of h
k3 = fn + h (c3ft + a31fnfy + a32fnfy) (4.24)
+ h2
a32c2ftfy + a21a32fnf2y +
c232ftt + a31c3fnfty
+c3a32fnfty +a2312f2nfyy + a31a32f
2nfyy +
a2322f2nfyy
(4.25)
+ h3
a32c22
2fyftt + a32a21c2fnfyfty +
a221a322
f2nfy
+a32c2c3ftfty + a21a32c3fnfyfty + a31a32c2fnftfyy+a21a31a32f
2nfyfyy + a232c2fnffyyt + a21a
232f
2nfyfyy
+c336fttt +
a31c23
2fnftty +
a32c23
2fnftty +
a231c32
f2nftyy
+a31a32c3f2nftyy +
a232c32
f2nftyy +a3316f3nfyyy
+a231a32
2f3nfyyy +
a31a232
2f3nfyyy +
a3326f3nfyyy
(4.26)
+O(h4)
(4.27)
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 22
We continue to write down the Taylor series expansion O(h4)
for k4.
k4 = f (tn + c4h, yn + ha41fn + ha42k2 + ha43k3) (4.28)
= fn + c4hft + h (a41fn + a42k2 + a43k3) fy (4.29)
+c24h
2
2ftt + c4h
2 (a41fn + a42k2 + a43k3) fty (4.30)
+1
2h2(a41fn + a42k2 + a43k3)
2fyy +
c34h3
6fttt (4.31)
+c242h3 (a41fn + a42k2 + a43k3) ftty (4.32)
+c4h
3
2(a41fn + a42k2 + a43k3)
2ftyy (4.33)
+1
6h2(a41fn + a42k2 + a43k3)
3fyyy +O
(h4)
(4.34)
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 23
Inserting (4.15) and (4.27) to (4.34)
k4 = fn + hc4ft + ha41fnfy (4.35)
+ ha42fy
fn + h (c2ft + a21fnfy)
+h2(c222ftt + a21c2fnfty +
a2212f2n
) (4.36)
+ ha43fy
fn + h (c3ft + a31fnfy + a32fnfy)
+h2
a32c2ftfy + a21a32fnf
2y +
c232ftt
+a31c3fnfty + c3a32fnfty +a2312f2nfyy
+a31a32f2nfyy +
a2322f2nfyy
(4.37)
+ h2c242ftt + h2a41c4fnfty + h2a42c4fty [fn + h (c2ft + a21fnfy)] (4.38)
+ h2a43c4fty [fn + h (c3ft + a31fnfy + a32fnfy)] (4.39)
+ h2a2412f2nfyy + h2
a2422fyy[fn + h (c2ft + a21fnfy)]
2(4.40)
+ h2a2432fyy[fn + h (c3ft + a31fnfy + a32fnfy)]
2(4.41)
+ h2a41a42fnfyy [fn + h (c2ft + a21fnfy)] (4.42)
+ h2a42a43fyy [fn + h (c2ft + a21fnfy)]× (4.43)
× [fn + h (c3ft + a31fnfy + a32fnfy)] (4.44)
+ h2a41a43fnfyy [fn + h (c3ft + a31fnfy + a32fnfy)] (4.45)
+ h3c346fttt + h3
c242
(a41fn + a42fn + a43fn) ftty (4.46)
+ h3c42
(a241f
2n + a242f
2n + a243f
2n + 2a41a42f
2n
+2a42a43f2n + 2a41a43f
2n
)ftyy (4.47)
+ h3
a3416f3n +
a3426f3n +
a3436f3n +
a241a422
f3n
+a241a43
2f3n +
a242a412
f3n +a242a43
2f3n +
a243a412
f3n
+a243a42
2f3n + a41a42a43f
3n
fyyy (4.48)
+O(h4)
(4.49)
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 24
Collecting terms respect to exponents of h
k4 = fn + h (c4ft + a41fnfy + a42fnfy + a43fnfy) (4.50)
+ h2
a42c2ftfy + a21a42fnf
2y + a43c3ftfy + a31a43fnf
2y
+a32a43fnf2y +
c242ftt + c4a41fnfty + c4a42fnfty
+c4a43fnfty +a2412f2nfyy +
a2422f2nfyy +
a2432f2nfyy
+a41a42f2nfyy + a42a43f
2nfyy + a41a43f
2nfyy
(4.51)
+ h3
a42c22
2fyftt + a21a42c2fnfyfty +
a42a221
2f2nfyfyy
+a43a32c2ftf2y + a21a32a43fnf
3y +
a43c23
2fyftt
+a31a43c3fnfyfty + a32a43c3fnfyfty +a231a43
2f2nfyfyy
+a31a32a43f2nfyfyy +
a232a432
f2nfyfyy + a42c2c4ftfty
+a21a42c4fnfyfty + a43c3c4ftfty + a31a43c4fnfyfty+a32a43c4fnfyfty + a242c2fnftfyy + a21a
242f
2nfyfyy
+a243c3fnftfyy + a31a243f
2nfyfyy + a32a
243f
2nfyfyy
+a41a42c2fnftfyy + a21a41a42f2nfyfyy + a42a43c3fnftfyy
+a31a42a43f2nfyfyy + a32a42a43f
2nfyfyy + a42a43c2fnftfyy
+a21a42a43f2nfyfyy + a41a43c3fnftfyy + a31a41a43f
2nfyfyy
+a32a41a43f2nfyfyy +
c346fttt +
a41c24
2fnftty +
a42c24
2fnftty
+a43c
24
2fnftty +
a241c42
f2nftyy +a242c4
2f2nftyy
+a243c4
2f2nftyy + a41a42c4f
2nftyy + a42a43c4f
2nftyy
+a41a43c4f2nftyy +
a3416f3nfyyy +
a3426f3nfyyy
+a3436f3nfyyy +
a241a422
f3nfyyy +a241a43
2f3nfyyy
+a41a
242
2f3nfyyy +
a242a432
f3nfyyy +a41a
243
2f3nfyyy
+a42a
243
2f3nfyyy + a41a42a43f
3nfyyy
(4.52)
+O(h4)
(4.53)
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 25
Inserting (4.10), (4.27) and (4.53) into (4.5)
y(n+1) (4.54)
= y(n) + h (b1fn + b2fn + b3fn + b4fn) (4.55)
+ h2(b2c2ft + a21b2fnfy + b3c3ft + a31b3fnfy + a32b3fnfy+b4c4ft + a41b4fnfy + a42b4fnfy + a43b4fnfy
)(4.56)
+ h3
b2c22
2ftt + b2c2a21fnfty +
a221b22
f2nfyy + a32b3c2ftfy
+a32b3a21fnfyfy +b3c
23
2ftt + c3b3a31fnfty + c3b3a32fnfty
+a231b3
2f2nfyy + a31a32b3fnfnfyy +
a232b32
f2nfyy + a42b4c2ftfy
+a42b4fya21fnfy + a43b4c3ftfy + a43a31b4fnf2y + +a43a32b4fnf
2y
+b4c
24
2ftt + c4b4a41fnfty + c4b4a42ftyfn + c4b4a43ftyfn
+a241b4
2f2nfyy +
a242b42
f2nfyy +a243b4
2f2nfyy + a41a42b4fyyf
2n
+a42a43b4fyyf2n + a41a43b4fyyf
2n
(4.57)
+ h4
b2c32
6fttt +
b2c22a212
fnftty +b2c2a
221
2f2nftyy +
a321b26
f3nfyyy
+a32b3c
22
2fttfy + a32b3c2a21fnftyfy +
a32a221b3
2f2nfyyfy
+c3a32b3c2ftfty + c3a32b3a21fnfyfty + a31a32b3c2fnftfyy+a31a32a21b3fnfnfyfyy + a232b3fnc2ftfyy + a232b3fna21fnfyfyy
+b3c
33
6fttt +
b3c23 (a31 + a32)
2fnftty +
b3c3a231
2f2nftyy
+b3c3a31a32fnfnftyy +b3c3a
232
2f2nftyy +
b3a331
6f3nfyyy
+b3a
231a322
f3nfyyy +b3a31a
232
2f3nfyyy +
b3a332
6f3nfyyy
+a42b4c
22
2fyftt + a42b4c2a21fnfyfty +
a42a221b4
2f2nfyfyy
+a43a32b4c2ftf2y + a43a32a21b4fnf
3y +
a43b4c23
2fyftt
+a43b4c3a31fnfyfty + a43b4c3a32fnfyfty +a43a
231b4
2f2nfyfyy
+a43a31a32b4f2nfyfyy +
a43a232b4
2f2nfyfyy + c4a42b4c2ftfty
+c4a42a21b4fnfyfty + c4a43c3b4ftfty + c4a43a31b4fnfyfty+c4a43a32b4fnfyfty + a242b4c2fnftfyy + a242a21b4f
2nfyfyy
+a243b4c3fnftfyy + a243a31b4f2nfyfyy + a243a32b4f
2nfyfyy
+a41a42b4c2fnftfyy + a41a21a42b4f2nfyfyy + a42a43b4c3fnftfyy
+a42a43a31b4f2nfyfyy + a42a43a32b4f
2nfyfyy + a42a43b4c2fnftfyy
+a42a43a21b4f2nfyfyy + a41a43b4c3fnftfyy + a41a43a31b4f
2nfyfyy
+a41a43a32b4f2nfyfyy +
b4c34
6fttt +
b4c24a412
fnftty +b4c
24a422
fnftty
+b4c
24a432
fnftty +c4b4a
241
2f2nftyy +
c4b4a242
2f2nftyy +
c4b4a243
2f2nftyy
+c4b4a41a42f2nftyy + c4a42a43b4f
2nftyy + c4a41a43b4f
2nftyy
+a341b4
6f3nfyyy +
a342b46
f3nfyyy +a343b4
6f3nfyyy +
a241a42b42
f3nfyyy
+a241a43b4
2f3nfyyy +
a242a41b42
f3nfyyy +a242a43b4
2f3nfyyy
+a243a41b4
2f3nfyyy +
a243a42b42
f3nfyyy + a41a42a43b4f3nfyyy
(4.58)
+O(h5)
(4.59)
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 26
4.1.2 Taylor Series Expansion Formula
We need to compute ytttt for Taylor series expansion below.
ytttt =d
dt
(ftt + ftfy + 2ffty + ff2y + f2fyy
)(4.60)
=(ftt + ftfy + 2ffty + ff2y + f2fyy
)t
(4.61)
+ f(ftt + ftfy + 2ffty + ff2y + f2fyy
)y
(4.62)
= fttt + fyftt + ftfty + 2ftfty + 2fftty + ftf2y + 2ffyfty (4.63)
+ 2fftfyy + f2ftyy + fftty + ffyfty + fftfyy + 2ffyfty (4.64)
+ 2f2ftyy + ff3y + 2f2fyfyy + 2f2fyfyy + f3fyyy (4.65)
= fttt + fyftt + 3ftfty + 3fftty + ftf2y + 5ffyfty + 3fftfyy (4.66)
+ 3f2ftyy + ff3y + 4f2fyfyy + f3fyyy (4.67)
Now we write down the Taylor series expansion of y in the neighborhood oftn with O
(h5).
yn+1 = yn + hfn +h2
2(ft + fnfy) (4.68)
+h3
6
(ftt + ftfy + 2fnfty + fnf
2y + f2nfyy
)(4.69)
+h4
24
(fttt + fyftt + 3ftfty + 3fnftty + ftf
2y + 5fnfyfty
+3fnftfyy + 3f2nftyy + fnf3y + 4f2nfyfyy + f3nfyyy
)(4.70)
+O(h5)
(4.71)
4.1.3 Derivation of System of Equations
Compare the coefficients of (4.68) and (4.59)
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 27
hfn : 1 = b1 + b2 + b3 + b4 (4.72)
h2ft :1
2= b2c2 + b3c3 + b4c4 (4.73)
h2fnfy :1
2= b2a21 + b3a31 + b3a32 + a41b4 + a42b4 + a43b4 (4.74)
h3ftt :1
6=b2c
22
2+b3c
23
2+b4c
24
2(4.75)
h3ftfy :1
6= a32b3c2 + a42b4c2 + a43b4c3 (4.76)
h3fnfty :1
3= b2c2a21 + c3b3a31 + c3b3a32 (4.77)
+ c4b4a41 + c4b4a42 + c4b4a43 (4.78)
h3fnf2y :
1
6= a32b3a21 + a42b4a21 + a43a31b4 + a43a32b4 (4.79)
h3f2nfyy :1
6=a221b2
2+a231b3
2+ a31a32b3 +
a232b32
+a241b4
2(4.80)
+a242b4
2+a243b4
2+ a41a42b4 + a42a43b4 + a41a43b4 (4.81)
h4fttt :1
24=b2c
32
6+b3c
33
6+b4c
34
6(4.82)
h4fyftt :1
24=a32b3c
22
2+a42b4c
22
2+a43b4c
23
2(4.83)
h4ftfty :1
8= c3a32b3c2 + c4a42b4c2 + c4a43c3b4 (4.84)
h4fnftty :1
8=b2c
22a212
+b3c
23 (a31 + a32)
2+b4c
24a412
(4.85)
+b4c
24a422
+b4c
24a432
(4.86)
h4ftf2y :
1
24= a43a32b4c2 (4.87)
h4fnfyfty :5
24= a32b3c2a21 + c3a32b3a21 + a42b4c2a21 (4.88)
+ c4a42a21b4 + c4a43a31b4 + a43b4c3a31 (4.89)
+ a43b4c3a32 + c4a43a32b4 (4.90)
h4fnftfyy :1
8= a31a32b3c2 + a232b3c2 + a242b4c2 + a243b4c3 (4.91)
+ a41a42b4c2 + a42a43b4c3 + a42a43b4c2 + a41a43b4c3 (4.92)
h4f2nftyy :1
8=b2c2a
221
2+b3c3a
231
2+ b3c3a31a32 +
b3c3a232
2(4.93)
+c4b4a
241
2+c4b4a
242
2+c4b4a
243
2+ c4b4a41a42 (4.94)
+ c4a42a43b4 + c4a41a43b4 (4.95)
h4fnf3y :
1
24= a43a32a21b4 (4.96)
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 28
h4f2nfyfyy :1
6=a32a
221b3
2+ a31a32a21b3 + a232b3a21 +
a42a221b4
2(4.97)
+a43a
231b4
2+ a43a31a32b4 +
a43a232b4
2+ a242a21b4 (4.98)
+ a243a31b4 + a243a32b4 + a41a21a42b4 + a42a43a31b4 (4.99)
+ a42a43a32b4 + a42a43a21b4 + a41a43a31b4 (4.100)
+ a41a43a32b4 (4.101)
h4f3nfyyy :1
24=a321b2
6+b3a
331
6+b3a
231a322
+b3a31a
232
2+b3a
332
6(4.102)
+a341b4
6+a342b4
6+a343b4
6+a241a42b4
2+a241a43b4
2(4.103)
+a242a41b4
2+a242a43b4
2+a243a41b4
2(4.104)
+a243a42b4
2+ a41a42a43b4 (4.105)
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 29
Hence, we obtain the system of equations
b1 + b2 + b3 + b4 = 1 (4.106)
b2c2 + b3c3 + b4c4 =1
2(4.107)
b2a21 + b3 (a31 + a32) + b4 (a41 + a42 + a43) =1
2(4.108)
b2c22 + b3c
23 + b4c
24 =
1
3(4.109)
b3a32c2 + b4 (a42c2 + a43c3) =1
6(4.110)
b2c2a21 + b3c3 (a31 + a32) + b4c4 (a41 + a42 + a43) =1
3(4.111)
b3a32a21 + b4 [a42a21 + a43 (a31 + a32)] =1
6(4.112)
b2a221 + b3(a31 + a32)
2+ b4(a41 + a42 + a43)
2=
1
3(4.113)
b2c32 + b3c
33 + b4c
34 =
1
4(4.114)
b3a32c22 + b4
(a42c
22 + a43c
23
)=
1
12(4.115)
b3c3a32c2 + b4c4 (a42c2 + a43c3) =1
8(4.116)
b2c22a21 + b3c
23 (a31 + a32) + b4c
24 (a41 + a42 + a43) =
1
4(4.117)
b4a43a32c2 =1
24(4.118){
b3a32a21 (c2 + c3)+b4 [a42a21 (c2 + c4) + a43 (a31 + a32) (c3 + c4)]
}=
5
24(4.119)
b3a32c2 (a31 + a32) + b4 (a42c2 + a43c3) (a41 + a42 + a43) =1
8(4.120)
b2c2a221 + b3c3(a31 + a32)
2+ b4c4(a41 + a42 + a43)
2=
1
4(4.121)
b4a43a32a21 =1
24(4.122) b3a32a21 [a21 + 2 (a31 + a32)]
+b4a42a21 [a21 + 2 (a41 + a42 + a43)]+b4a43 (a31 + a32) [a31 + a32 + 2 (a43 + a42 + a41)]
=1
3(4.123)
b2a321 + b3(a31 + a32)
3+ b4(a41 + a42 + a43)
3=
1
4(4.124)
4.1.4 Solutions of System of Equations
We now solve the above system of equations.We take
c2 = α (4.125)
c3 = β (4.126)
c4 = γ (4.127)
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 30
as three free variables.Then, our system of equations becomes
b1 + b2 + b3 + b4 = 1 (4.128)
αb2 + βb3 + γb4 =1
2(4.129)
b2a21 + b3 (a31 + a32) + b4 (a41 + a42 + a43) =1
2(4.130)
α2b2 + β2b3 + γ2b4 =1
3(4.131)
αb3a32 + b4 (αa42 + βa43) =1
6(4.132)
αb2a21 + βb3 (a31 + a32) + γb4 (a41 + a42 + a43) =1
3(4.133)
b3a32a21 + b4 [a42a21 + a43 (a31 + a32)] =1
6(4.134)
b2a221 + b3(a31 + a32)
2+ b4(a41 + a42 + a43)
2=
1
3(4.135)
α3b2 + β3b3 + γ3b4 =1
4(4.136)
α2b3a32 + b4(α2a42 + β2a43
)=
1
12(4.137)
αβb3a32 + γb4 (αa42 + βa43) =1
8(4.138)
α2b2a21 + β2b3 (a31 + a32) + γ2b4 (a41 + a42 + a43) =1
4(4.139)
αb4a43a32 =1
24(4.140){
b3a32a21 (α+ β)+b4 [a42a21 (α+ γ) + a43 (a31 + a32) (β + γ)]
}=
5
24(4.141)
αb3a32 (a31 + a32) + b4 (αa42 + βa43) (a41 + a42 + a43) =1
8(4.142)
αb2a221 + βb3(a31 + a32)
2+ γb4(a41 + a42 + a43)
2=
1
4(4.143)
b4a43a32a21 =1
24(4.144) b3a32a21 [a21 + 2 (a31 + a32)]
+b4a42a21 [a21 + 2 (a41 + a42 + a43)]+b4a43 (a31 + a32) [a31 + a32 + 2 (a43 + a42 + a41)]
=1
3(4.145)
a321b2 + b3(a31 + a32)3
+ b4(a41 + a42 + a43)3
=1
4(4.146)
We now need to focus on three special equations of the above system.
αb2 + βb3 + γb4 =1
2(4.147)
α2b2 + β2b3 + γ2b4 =1
3(4.148)
α3b2 + β3b3 + γ3b4 =1
4(4.149)
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 31
Case (α = β) ∨ (β = γ) ∨ (γ = α).Reader do this case as exercises.
Case α, β, γ are pairwise distinct.Solving this system of three equations respect to b2, b3, b4, we obtain
b2 = − 4β + 4γ − 6βγ − 3
12α (α− β) (α− γ)(4.150)
b3 = − 4γ + 4α− 6γα− 3
12β (β − γ) (β − α)(4.151)
b4 = − 4α+ 4β − 6αβ − 3
12γ (γ − α) (γ − β)(4.152)
Then we use (4.128) to obtain
b1 =4 (α+ β + γ)− 6 (αβ + βγ + γα) + 12αβγ − 3
12αβγ(4.153)
Now using b1, b2, b3, b4, we need to focus on the following three equations ofthe remaining system.
αb3a32 + b4 (αa42 + βa43) =1
6(4.154)
α2b3a32 + b4(α2a42 + β2a43
)=
1
12(4.155)
αβb3a32 + γb4 (αa42 + βa43) =1
8(4.156)
Solving this system of three equations respect to a32, a42, a43, we obtain
a32 =β (4γ − 3) (α− β)
2α (4α+ 4γ − 6αγ − 3)(4.157)
a42 =γ (α− γ)
(4β2 − 5β + 3α+ 2γ − 4αγ
)2α (6α2β − 4α2 − 6αβ2 + 3α+ 4β2 − 3β)
(4.158)
a43 =γ (1− 2α) (γ − α) (γ − β)
β (6α2β − 4α2 − 6αβ2 + 3α+ 4β2 − 3β)(4.159)
Now, we only need to solve a21, a31, a41. To do this, we need to focus on thefollowing three equations of the remaining system.
b2a21 + b3a31 + b4a41 =1
2− b3a32 − b4a42 − b4a43 (4.160)
αb2a21 + βb3a31 + γb4a41 =1
3− βb3a32 − γb4a42 − γb4a43 (4.161)
(b3a32 + b4a42) a21 + b4a43a31 =1
6− b4a43a32 (4.162)
We solve this system of three equations respect to a21, a31, a41 by the followingMatlab routine because the formulas are quite long.
format long
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 32
syms a b c; % a=alpha, b=beta, c=gamma
A = [a b c; a^2 b^2 c^2; a^3 b^3 c^3];
v=[1/2;1/3;1/4];
B = A^-1*v;
b2 = B(1);
b3 = B(2);
b4 = B(3);
A1 = [a*b3 a*b4 b*b4;
a^2*b3 a^2*b4 b^2*b4;
a*b*b3 c*b4*a c*b4*b];
v1 = [1/6;1/12;1/8];
B1 = A1^-1*v1;
a32 = B1(1)
a42 = B1(2)
a43 = B1(3)
A2 = [b2 b3 b4;a*b2 b*b3 c*b4;(b3*a32+b4*a42) b4*a43 0];
v2 = [1/2-b3*32-b4*a42-b4*a43;
1/3-b*b3*a32-c*b4*a42-c*b4*a43;
1/6-b4*a43*a32];
B2 = A2^-1*v2;
a21 = B2(1)
a31 = B2(2)
a41 = B2(3)
This Matlab routine returns the formulas of a21, a31, a41 in terms of α, β, γ.Hence, we obtain the solutions of our system of equations in terms of α, β, γ.Checking whether this solutions satisfies the remaining system of equations isjust computation matter. Although those computations is quite complicated byhand, checking by Matlab is quite easy and there is no benefit to representthose computations here. You should check yourself.
In practice, we don’t need to know the final three formulas of a21, a31, a41 interms of α, β, γ. For each 3 tuples α, β, γ, we can easily solve the other unknownsby the process described above.
We have solved (4.106)-(4.124) completely. �
4.1.5 Some Cases
Case α =1
2, β =
1
2, γ = 1. Using the above process, we obtain
01
2
1
21
20
1
21 0 0 1
1
6
1
3
1
3
1
6
(4.163)
This Butcher tableau appears in [4], p.100.
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 33
Case α =1
3, β =
2
3, γ = 1.
01
3
1
32
3−1
31
1 1 −1 11
8
3
8
3
8
1
8
(4.164)
This Butcher tableau appears in [5].
4.2 Matlab Implementation
4.2.1 Curtiss-Hirchfelder Equation
In this subsection, we will use Runge Kutta order 4 method to solve numericallythe Curtiss-Hirchfelder equation.
Definition 4.1. The Curtiss-Hirchfelder equation is an ordinary differentialequation (ODE) which has the following form
dy
dt= −50 (y − cos t) (4.165)
y (0) = 1 (4.166)
In general,
dy
dt= f (t, y) (4.167)
y (x0) = y0 (4.168)
The following Matlab routines aims at
1. Approximating solution of (4.165) by using Runge Kutta order 4 method.
2. Compute absolute errors and relative errors and plot the obtained numer-ical solutions and errors.
4.2.1.1 Subroutine s.m
This subroutine provides the exact solution of (4.165).
function s = s(t)
s = 50/2501*(50*cos(t)+sin(t)) + exp(-50*t)/2501;
4.2.1.2 Subroutine f.m
This subroutine provides the function f in RHS of (4.165). Users can modifythese functions later.
function f = f(t,y)
f = -50*y + 50*cos(t);
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 34
4.2.1.3 Subroutine x.m
This subroutine provides the Runge Kutta order 4 method.
function x = x(a,b,c,h,t,y)
k1 = f(t,y);
k2 = f(t+c(2)*h,y+h*a(2,1)*k1);
k3 = f(t+c(3)*h,y+h*(a(3,1)*k1+a(3,2)*k2));
k4 = f(t+c(4)*h,y+h*(a(4,1)*k1+a(4,2)*k2+a(4,3)*k3));
x = h*(b(1)*k1+b(2)*k2+b(3)*k3+b(4)*k4);
4.2.1.4 Main Routine RK4
close all
clear all
clc
format long
tic
%% Initial.
A1(1) = 1;
A2(1) = 1;
% A3(1) = 1;
N=1000;
h=25/N;
t = 0:h:25;
%% Coefficients
a1 = [0 0 0 0 ;
1/2 0 0 0 ;
0 1/2 0 0 ;
0 0 1 0];
b1 = [1/6 1/3 1/3 1/6];
c1 = [0 1/2 1/2 1];
a2 = [0 0 0 0 ;
1/3 0 0 0 ;
-1/3 1 0 0 ;
1 -1 1 0];
b2 = [1/8 3/8 3/8 1/8];
c2 = [0 1/3 2/3 1];
%% Numerical Solution.
for n=1:N
A1(n+1) = A1(n) + x(a1,b1,c1,h,t(n),A1(n));
A2(n+1) = A2(n) + x(a2,b2,c2,h,t(n),A2(n));
end
%% Plot Numerical Solution
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 35
figure(1)
hold on
plot(t,s(t),’b’);
plot(t,A1,’r’);
legend(’Exact Solution’,’Numerical Solution’);
title(’Numerical Solution (Butcher Table 1)’);
figure(2)
hold on
plot(t,s(t),’b’);
plot(t,A2,’r’);
legend(’Exact Solution’,’Numerical Solution’);
title(’Numerical Solution (Butcher Table 2)’);
%% Absolute Error.
display(’Absolute Error 1’)
ae1 = h*sum(abs(A1-s(t)))
display(’Absolute Error 2’)
ae2 = h*sum(abs(A2-s(t)))
figure(3)
hold on
plot(t,abs(A1-s(t)),’g’);
plot(t,abs(A2-s(t)),’b’);
legend(’a1 b1 c1’,’a2 b2 c2’);
title(’Absolute Error’);
%% Relative Error.
display(’Relative Error 1’)
re1 = h*sum(abs((A1-s(t))./s(t)))
display(’Relative Error 2’)
re2 = h*sum(abs((A2-s(t))./s(t)))
figure(4)
hold on
plot(t,abs((A1-s(t))./A1),’g’);
plot(t,abs((A2-s(t))./A2),’b’);
legend(’a1 b1 c1’,’a2 b2 c2’);
title(’Relative Error’);
toc
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 36
4.2.1.5 Results
Figure 4.1: Numerical Solutions.
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 37
Figure 4.2: Absolute Errors.
4.2.2 Brusselator Equation
Definition 4.2. The Brusselator equation is the following system of equations
dy1dt
= 1− 4y1 + y21y2 (4.169)
dy2dt
= 3y1 − y21y2 (4.170)
In general,
dy1dt
= f1 (t, y1, y2) (4.171)
dy2dt
= f2 (t, y1, y2) (4.172)
In vector form y = (y1, y2),
dy
dt= f (t, y) (4.173)
4.2.2.1 Subroutine f.m
This subroutine provides f1 and f2 in the RHS of (4.171) and (4.172). Userscan modify these functions later.
function f = f(t,y)
f(1) = 1-4*y(1)+y(1)^2*y(2);
f(2) = 3*y(1)-y(1)^2*y(2);
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 38
Figure 4.3: Relative Errors.
4.2.2.2 Subroutine x.m
This subroutine provides the Runge Kutta order 4 method.
function x = x(a,b,c,h,t,y)
k1 = f(t,y);
k2 = f(t+c(2)*h,y+h*a(2,1)*k1);
k3 = f(t+c(3)*h,y+h*(a(3,1)*k1+a(3,2)*k2));
k4 = f(t+c(4)*h,y+h*(a(4,1)*k1+a(4,2)*k2+a(4,3)*k3));
x = h*(b(1)*k1+b(2)*k2+b(3)*k3+b(4)*k4);
4.2.2.3 Main Routine RK4.m
clear all
close all
clc
format long
tic
%% Initial for Reference Solutions.
N0 = 10^6;
h0= 20/N0;
t0 = 0:h0:20;
B1 = zeros(N0,2);
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 39
B1(1,1) = 1.5;
B1(1,2) = 3;
B2 = zeros(N0,2);
B2(1,1) = 1.5;
B2(1,2) = 3;
%% Initial for Numerical Solutions.
N = 10^4;
h = 20/N;
t = 0:h:20;
A1 = zeros(N,2);
A1(1,1) = 1.5;
A1(1,2) = 3;
A2 = zeros(N,2);
A2(1,1) = 1.5;
A2(1,2) = 3;
A3 = zeros(N,2);
A3(1,1) = 1.5;
A3(1,2) = 3;
% Step
step = N0/N;
%% Runge Kutta initials.
% Coefficients
a1 = [0 0 0 0 ;
1/2 0 0 0 ;
0 1/2 0 0 ;
0 0 1 0];
b1 = [1/6 1/3 1/3 1/6];
c1 = [0 1/2 1/2 1];
a2 = [0 0 0 0 ;
1/3 0 0 0 ;
-1/3 1 0 0 ;
1 -1 1 0];
b2 = [1/8 3/8 3/8 1/8];
c2 = [0 1/3 2/3 1];
%% Reference Solutions.
for n=1:N0
B1(n+1,:) = B1(n,:) + x(a1,b1,c1,h0,t0(n),B1(n,:));
B2(n+1,:) = B2(n,:) + x(a2,b2,c2,h0,t0(n),B2(n,:));
end
%% Numerical Solutions, Absolute Errors and Relative Errors.
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 40
ae1 = zeros(N+1,2);
ae2 = zeros(N+1,2);
re1 = zeros(N+1,2);
re2 = zeros(N+1,2);
for n=1:N
% Numerical Solutions
A1(n+1,:) = A1(n,:) + x(a1,b1,c1,h,t(n),A1(n,:));
A2(n+1,:) = A2(n,:) + x(a2,b2,c2,h,t(n),A2(n,:));
% Absolute Errors
ae1(n,:) = h.*abs(A1(n,:)-B1(step*(n-1)+1,:));
ae2(n,:) = h.*abs(A2(n,:)-B2(step*(n-1)+1,:));
% ae1(n,1) = abs((A1(n,1)-s(1,t));
% ae1(n,2) = abs((A1(n,2)-s(2,t));
% ae2(n,1) = abs((A2(n,i)-s(1,t));
% ae2(n,2) = abs((A2(n,i)-s(2,t));
% Relative Errors
re1(n,:) = h.*abs((A1(n,:) ...
-B1(step*(n-1)+1,:))./B1(step*(n-1)+1,:));
re2(n,:) = h.*abs((A2(n,:) ...
-B2(step*(n-1)+1,:))./B2(step*(n-1)+1,:));
% re1(n,1) = abs((A1(n,1)-s(1,t))./s(i,t));
% re1(n,2) = abs((A1(n,2)-s(2,t))./s(i,t));
% re2(n,1) = abs((A2(n,i)-s(1,t))./s(i,t));
% re2(n,2) = abs((A2(n,i)-s(2,t))./s(i,t));
end
% Absolute Errors
display(’Absolute Error of Table 1’)
ae1_y1 = h*sum(ae1(:,1))
ae1_y2 = h*sum(ae1(:,2))
display(’Absolute Error of Table 2’)
ae2_y1 = h*sum(ae2(:,1))
ae2_y2 = h*sum(ae2(:,2))
% Relative Errors
display(’Relative Error of Table 1’)
re1_y1 = h*sum(re1(:,1))
re1_y2 = h*sum(re1(:,2))
display(’Relative Error of Table 2’)
re2_y1 = h*sum(re2(:,1))
re2_y2 = h*sum(re2(:,2))
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 41
%% Plot Numerical Solution
figure(1)
subplot(2,1,1)
hold on
% plot(t,s(1,t),’b’)
plot(t0,B1(:,1),’b’)
plot(t,A1(:,1),’r’)
legend(’Exact/Reference’,’Numerical Solution’);
title(’Numerical Solution for Y1 (Butcher Table 1)’);
subplot(2,1,2)
hold on
% plot(t,s(2,t),’b’)
plot(t0,B1(:,2),’b’)
plot(t,A1(:,2),’r’)
legend(’Exact/Reference’,’Numerical Solution’);
title(’Numerical Solution for Y2 (Butcher Table 1)’);
figure(2)
subplot(2,1,1)
hold on
% plot(t,s(1,t),’b’)
plot(t0,B2(:,1),’b’)
plot(t,A2(:,1),’r’)
legend(’Exact/Reference’,’Numerical Solution’);
title(’Numerical Solution for Y1 (Butcher Table 2)’);
subplot(2,1,2)
hold on
% plot(t,s(2,t),’b’)
plot(t0,B2(:,2),’b’)
plot(t,A2(:,2),’r’)
legend(’Exact/Reference’,’Numerical Solution’);
title(’Numerical Solution for Y2 (Butcher Table 2)’);
%% Plot: Dependency of y2 with respect to y1.
figure(3)
hold on
plot(A1(:,1),A1(:,2),’b’);
plot(A2(:,1),A2(:,2),’g’);
% plot(A3(:,1),A3(:,2),’r’);
legend(’a1 b1 c1’,’a2 b2 c2’);
title(’Dependency of y2 with respect to y1’);
%% Plot Absolute Errors.
figure(4)
subplot(2,1,1)
hold on
plot(t,ae1(:,1),’b’);
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 42
plot(t,ae2(:,1),’g’);
% plot(t,ae3(:,1),’r’);
legend(’a1 b1 c1’,’a2 b2 c2’);
title(’Absolute Errors Y1’);
subplot(2,1,2)
hold on
plot(t,ae1(:,2),’b’);
plot(t,ae2(:,2),’g’);
% plot(t,ae3(:,2),’r’);
legend(’a1 b1 c1’,’a2 b2 c2’);
title(’Absolute Errors Y2’);
%% Plot Relative Errors.
figure(5)
subplot(2,1,1)
hold on
plot(t,re1(:,1),’b’);
plot(t,re2(:,1),’g’);
% plot(t,re3(:,1),’r’);
legend(’a1 b1 c1’,’a2 b2 c2’);
title(’Relative Errors Y1’);
subplot(2,1,2)
hold on
plot(t,re1(:,2),’b’);
plot(t,re2(:,2),’g’);
% plot(t,re3(:,2),’r’);
legend(’a1 b1 c1’,’a2 b2 c2’);
title(’Relative Errors Y2’);
toc
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 43
4.2.2.4 Results
Figure 4.4: Numerical Solutions.
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 44
Figure 4.5: Dependency of y2 with respect to y1.
4.2.3 Examples
4.2.3.1 Subroutine s2.m
function s2 = s2(t)
s2 = [3*exp(2*t)-2*exp(3*t);-3*exp(2*t)+4*exp(3*t)];
4.2.3.2 Subroutine f2.m
function f2 = f2(t,y)
% f2=[y(1)-y(2),2*y(1)+4*y(2)];
f2(1) = y(1)-y(2);
f2(2) = 2*y(1)+4*y(2);
4.2.3.3 Subroutine x2.m
function x2 = x2(a,b,c,h,t,y)
k1 = f2(t,y);
k2 = f2(t+c(2)*h,y+h*a(2,1)*k1);
k3 = f2(t+c(3)*h,y+h*(a(3,1)*k1+a(3,2)*k2));
k4 = f2(t+c(4)*h,y+h*(a(4,1)*k1+a(4,2)*k2+a(4,3)*k3));
x2 = h*(b(1)*k1+b(2)*k2+b(3)*k3+b(4)*k4);
4.2.3.4 Main Routine RK4ex2.m
clear all
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 45
Figure 4.6: Absolute Errors.
close all
clc
format long
tic
% %% Initial for Reference Solutions.
% N0 = 10^6;
% h0= 20/N0;
% t0 = 0:h0:20;
%
% B1 = zeros(N0,2);
% B1(1,1) = 1;
% B1(1,2) = 1;
%
% B2 = zeros(N0,2);
% B2(1,1) = 1;
% B2(1,2) = 1;
%% Initial for Numerical Solutions.
N = 10^4;
h = 1/N;
t = 0:h:1;
A1 = zeros(N+1,2);
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 46
Figure 4.7: Relative Errors.
A1(1,1) = 1;
A1(1,2) = 1;
A2 = zeros(N+1,2);
A2(1,1) = 1;
A2(1,2) = 1;
A3 = zeros(N+1,2);
A3(1,1) = 1;
A3(1,2) = 1;
% Step
% step = N0/N;
%% Runge Kutta initials.
% Coefficients
a1 = [0 0 0 0 ;
1/2 0 0 0 ;
0 1/2 0 0 ;
0 0 1 0];
b1 = [1/6 1/3 1/3 1/6];
c1 = [0 1/2 1/2 1];
a2 = [0 0 0 0 ;
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 47
1/3 0 0 0 ;
-1/3 1 0 0 ;
1 -1 1 0];
b2 = [1/8 3/8 3/8 1/8];
c2 = [0 1/3 2/3 1];
% %% Reference Solutions.
% for n=1:N0
% B1(n+1,:) = B1(n,:) + x(a1,b1,c1,h0,t0(n),B1(n,:));
% B2(n+1,:) = B2(n,:) + x(a2,b2,c2,h0,t0(n),B2(n,:));
% end
s=s2(t)’;
%% Numerical Solutions, Absolute Errors and Relative Errors.
ae1 = zeros(N+1,2);
ae2 = zeros(N+1,2);
re1 = zeros(N+1,2);
re2 = zeros(N+1,2);
for n=1:N
% Numerical Solutions
A1(n+1,:) = A1(n,:) + x2(a1,b1,c1,h,t(n),A1(n,:));
A2(n+1,:) = A2(n,:) + x2(a2,b2,c2,h,t(n),A2(n,:));
% Absolute Errors
% ae1(n,:) = h.*abs(A1(n,:)-B1(step*(n-1)+1,:));
ae1 = (abs(A1-s));
% ae2(n,:) = h.*abs(A2(n,:)-B2(step*(n-1)+1,:));
ae2 = (abs(A2-s));
% ae1(n,1) = abs((A1(n,1)-s(1,t));
% ae1(n,2) = abs((A1(n,2)-s(2,t));
% ae2(n,1) = abs((A2(n,i)-s(1,t));
% ae2(n,2) = abs((A2(n,i)-s(2,t));
% Relative Errors
% re1(n,:) = h.*abs((A1(n,:)-B1(step*(n-1)+1,:))./B1(step*(n-1)+1,:));
re1 = (abs((A1-s)./s));
% re2(n,:) = h.*abs((A2(n,:)-B2(step*(n-1)+1,:))./B2(step*(n-1)+1,:));
re2 = (abs((A2-s)./s));
% re1(n,1) = abs((A1(n,1)-s(1,t))./s(i,t));
% re1(n,2) = abs((A1(n,2)-s(2,t))./s(i,t));
% re2(n,1) = abs((A2(n,i)-s(1,t))./s(i,t));
% re2(n,2) = abs((A2(n,i)-s(2,t))./s(i,t));
end
% Absolute Errors
display(’Absolute Error of Table 1’)
ae1_y1 = h*sum(ae1(:,1))
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 48
ae1_y2 = h*sum(ae1(:,2))
display(’Absolute Error of Table 2’)
ae2_y1 = h*sum(ae2(:,1))
ae2_y2 = h*sum(ae2(:,2))
% Relative Errors
display(’Relative Error of Table 1’)
re1_y1 = h*sum(re1(:,1))
re1_y2 = h*sum(re1(:,2))
display(’Relative Error of Table 2’)
re2_y1 = h*sum(re2(:,1))
re2_y2 = h*sum(re2(:,2))
%% Plot Numerical Solution
figure(1)
subplot(2,1,1)
hold on
% plot(t,s(1,t),’b’)
plot(t,s(:,1),’b’)
plot(t,A1(:,1),’r’)
legend(’Exact/Reference’,’Numerical Solution’);
title(’Numerical Solution for Y1 (Butcher Table 1)’);
subplot(2,1,2)
hold on
% plot(t,s(2,t),’b’)
plot(t,s(:,2),’b’)
plot(t,A1(:,2),’r’)
legend(’Exact/Reference’,’Numerical Solution’);
title(’Numerical Solution for Y2 (Butcher Table 1)’);
figure(2)
subplot(2,1,1)
hold on
% plot(t,s(1,t),’b’)
plot(t,s(:,1),’b’)
plot(t,A2(:,1),’r’)
legend(’Exact/Reference’,’Numerical Solution’);
title(’Numerical Solution for Y1 (Butcher Table 2)’);
subplot(2,1,2)
hold on
% plot(t,s(2,t),’b’)
plot(t,s(:,2),’b’)
plot(t,A2(:,2),’r’)
legend(’Exact/Reference’,’Numerical Solution’);
title(’Numerical Solution for Y2 (Butcher Table 2)’);
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 49
%% Plot: Dependency of y2 with respect to y1.
figure(3)
hold on
plot(A1(:,1),A1(:,2),’b’);
plot(A2(:,1),A2(:,2),’g’);
% plot(A3(:,1),A3(:,2),’r’);
legend(’Butcher Table 1’,’Butcher Table 2’);
title(’Dependency of y2 with respect to y1’);
%% Plot Absolute Errors.
figure(4)
subplot(2,1,1)
hold on
plot(t,ae1(:,1),’b’);
plot(t,ae2(:,1),’g’);
% plot(t,ae3(:,1),’r’);
legend(’Butcher Table 1’,’Butcher Table 2’);
title(’Absolute Errors Y1’);
subplot(2,1,2)
hold on
plot(t,ae1(:,2),’b’);
plot(t,ae2(:,2),’g’);
% plot(t,ae3(:,2),’r’);
legend(’Butcher Table 1’,’Butcher Table 2’);
title(’Absolute Errors Y2’);
%% Plot Relative Errors.
figure(5)
subplot(2,1,1)
hold on
plot(t,re1(:,1),’b’);
plot(t,re2(:,1),’g’);
% plot(t,re3(:,1),’r’);
legend(’Butcher Table 1’,’Butcher Table 2’);
title(’Relative Errors Y1’);
subplot(2,1,2)
hold on
plot(t,re1(:,2),’b’);
plot(t,re2(:,2),’g’);
% plot(t,re3(:,2),’r’);
legend(’Butcher Table 1’,’Butcher Table 2’);
title(’Relative Errors Y2’);
toc
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 50
4.2.3.5 Results
Figure 4.8: Numerical Solutions.
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 51
Figure 4.9: Numerical Solutions.
Figure 4.10: Dependency of y2 with respect to y1.
CHAPTER 4. RUNGE KUTTA ORDER 4 METHOD 52
Figure 4.11: Absolute Errors.
Figure 4.12: Relative Errors.
Alphabetical Index
Aabsolute errors 33autonomous form 1
BBrusselator equation 37Butcher table 3Butcher tableau 2
CCurtiss-Hirchfelder equation 33
EEuler’s method 3explicit Euler’s method 3
Ffamily of explicit Runge Kutta
methods 2
Iinitial value problems 1iterative method 1
KKutta’s third order method 19
Mmesh 2
Nnon-autonomous form 1
Oorder of accuracy 1
Rrelative errors 33Runge Kutta method 1Runge Kutta method of second order
7Runge Kutta order 1 method 3Runge Kutta order 2 method 4Runge Kutta order 3 method 8Runge Kutta order 4 method 20, 33
Sstep size 2stiff problems 1
TTaylor’s series 1
53
Bibliography
[1] Richard L. Burden, J. Douglas Faires, Numerical Analysis, Ninth Edition.
[2] David Goeken, Olin Johnson, Fifth-order Runge-Kutta with higher orderderivative approximations, Electronic Journal of Differential Equations,Conference 02, 1999, pp. 1-9.
[3] J. C. Butcher, On fifth and sixth order explicit Runge-Kutta methods: Or-der conditions and Order barriers, Canadian applied mathematics quar-terly, Volume 17, Number 3, Fall 2009.
[4] John Butcher, Runge-Kutta methods for ordinary differential equations,The University of Auckland New Zealand, COE Workshop on NumericalAnalysis, Kyushu University, May 2005.
[5] https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods
[6] https://en.wikipedia.org/wiki/List_of_Runge%E2%80%93Kutta_
methods
54