Sie sind auf Seite 1von 11

Runge-Kutta 2nd Order Method for

Ordinary Differential Equations


After reading this chapter, you should be able to:
1. understand the Runge-Kutta 2nd order method for ordinary differential equations
and how to use it to solve problems.
What is the Runge-Kutta 2nd order method?
The Runge-Kutta 2nd order method is a numerical technique used to solve an ordinary
differential equation of the form
( ) ( )
0
0 , , y y y x f
dx
dy

Only first order ordinary differential equations can e solved y using the Runge-Kutta 2nd
order method. !n other sections, "e "ill discuss ho" the #uler and Runge-Kutta methods are
used to solve higher order ordinary differential equations or cou$led %simultaneous&
differential equations.
'o" does one "rite a first order differential equation in the aove form(
Example 1
Re"rite
( ) ) 0 , * . 1 2 +

y e y
dx
dy
x
in

0
& 0 % &, , % y y y x f
dx
dy

form.
Solution
( ) ) 0 , * . 1 2 +

y e y
dx
dy
x
( ) ) 0 , 2 * . 1

y y e
dx
dy
x
!n this case
( ) y e y x f
x
2 * . 1 ,

0+.0*.1
The Runge Kutta method
Example 2
Re"rite
( ) ) 0 &, * sin% 2
2 2
+ y x y x
dx
dy
e
y
in
0
& 0 % &, , % y y y x f
dx
dy

form.
Solution
( ) ) 0 &, * sin% 2
2 2
+ y x y x
dx
dy
e
y
( ) ) 0 ,
& * sin% 2
2 2

y
e
y x x
dx
dy
y
!n this case
( )
y
e
y x x
y x f
2 2
& * sin% 2
,

Runge-Kutta 2
nd
order method
#uler,s method is given y
( ) h y x f y y
i i i i
,
1
+
+
%1&
"here
0
0
x
& %
0 0
x y y
i i
x x h
+1
To understand the Runge-Kutta 2nd order method, "e need to derive #uler,s method from
the Taylor series.
( ) ( ) ( ) ...
- *
1
- 2
1
*
1
,
*
*
2
1
,
2
2
1
,
1
+ + + +
+ + + + i i
y x
i i
y x
i i
y x
i i
x x
dx
y d
x x
dx
y d
x x
dx
dy
y y
i i i i
i i

( ) ( ) ( ) ... & , % . .
- *
1
& , % .
- 2
1
& , %
*
1
2
1 1
+ + + +
+ + + i i i i i i i i i i i i i
x x y x f x x y x f x x y x f y

%2&
/s you can see the first t"o terms of the Taylor series
( ) h y x f y y
i i i i
,
1
+
+
are #uler,s method and hence can e considered to e the Runge-Kutta 1st order method.
The true error in the a$$ro0imation is given y
( ) ( )
...
- *
,
- 2
,
* 2
+

+

h
y x f
h
y x f

i i i i
t
%*&
1o "hat "ould a 2nd order method formula loo2 li2e. !t "ould include one more term of the
Taylor series as follo"s.
( ) ( )
2
1
,
- 2
1
, h y x f h y x f y y
i i i i i i
+ +
+
%3&
4et us ta2e a generic e0am$le of a first order ordinary differential equation
The Runge Kutta method
( ) ) 0 , *
2


y y e
dx
dy
x

( ) y e y x f
x
* ,
2


5o" since y is a function of x,
( )
( ) ( )
dx
dy
y
y x f
x
y x f
y x f


, ,
,

%)&
( ) ( ) [ ]( ) y e y e
y
y e
x
x x x
* * *
2 2 2


( ) y e e
x x
* & * % 2
2 2
+

y e
x
6 )
2
+

The 2nd order formula for the aove e0am$le "ould e
( ) ( )
2
1
,
- 2
1
, h y x f h y x f y y
i i i i i i
+ +
+
( ) ( )
2 2 2
6 )
- 2
1
* h y e h y e y
i
x
i
x
i
i i
+ + +

'o"ever, "e already see the difficulty of having to find
( ) y x f ,
in the aove method.
7hat Runge and Kutta did "as "rite the 2nd order method as
( ) h ! a ! a y y
i i 2 2 1 1 1
+ +
+
%8&
"here
( )
i i
y x f ! ,
1

( ) h ! q y h p x f !
i i 1 11 1 2
, + +
%9&
This form allo"s one to ta2e advantage of the 2nd order method "ithout having to calculate
( ) y x f ,
.
1o ho" do "e find the un2no"ns
1
a ,
2
a ,
1
p and
11
q . 7ithout $roof %see
/$$endi0 for $roof&, equating #quation %3& and %8& , gives three equations.
1
2 1
+ a a
2
1
1 2
p a
2
1
11 2
q a
1ince "e have * equations and 3 un2no"ns, "e can assume the value of one of the
un2no"ns. The other three "ill then e determined from the three equations. :enerally the
value of
2
a is chosen to evaluate the other three constants. The three values generally used
for
2
a are
2
1
, 1 and
*
2
, and are 2no"n as 'eun,s ;ethod, the mid$oint method and
Ralston,s method, res$ectively.
'eun,s ;ethod
'ere
2
1
2
a
is chosen, giving
2
1
1
a
1
1
p
The Runge Kutta method
1
11
q
resulting in
h ! ! y y
i i

,
_

+ +
+ 2 1 1
2
1
2
1
%+&
"here
( )
i i
y x f ! ,
1


%6a&
( ) h ! y h x f !
i i 1 2
, + +
%6&
This method is gra$hically e0$lained in <igure 1.
Figure 1 Runge-Kutta 2nd order method %'eun,s method&.
;id$oint ;ethod
'ere 1
2
a is chosen, giving
0
1
a
2
1
1
p
2
1
11
q
resulting in
h ! y y
i i 2 1
+
+
%10&
"here
( )
i i
y x f ! ,
1


%11a&

,
_

+ + h ! y h x f !
i i 1 2
2
1
,
2
1
%11&
Ralston,s ;ethod
'ere
*
2
2
a
is chosen, giving
x
i
x
i"#
x
y


predicted
y
i
( )
i i
y x f $lope ,
( ) h ! y h x f $lope
i i 1
, + +
( ) ( ) [ ]
i i i i
y x f h ! y h x f $lope Average , ,
2
1

1
+ + +
The Runge Kutta method
*
1
1
a
3
*
1
p
3
*
11
q
resulting in
h ! ! y y
i i

,
_

+ +
+ 2 1 1
*
2
*
1
%12&
"here
( )
i i
y x f ! ,
1


%1*a&

,
_

+ + h ! y h x f !
i i 1 2
3
*
,
3
*
%1*&
Example 3
/ all at 1200K is allo"ed to cool do"n in air at an amient tem$erature of *00K.
/ssuming heat is lost only due to radiation, the differential equation for the tem$erature of
the all is given y
& 10 +1 % 10 2089 . 2
+ 3 12 -

dt
d

"here is in K and t in seconds. <ind the tem$erature at 3+0 t seconds using Runge-
Kutta 2nd order method. /ssume a ste$ si=e of 230 h seconds.
Solution
( )
+ 3 12
10 +1 10 2089 . 2

dt
d
( ) ( )
+ 3 12
10 +1 10 2089 . 2 ,

t f
>er 'eun,s method given y #quations %+& and %6&
h ! !
i i

,
_

+ +
+ 2 1 1
2
1
2
1

( )
i i
t f ! ,
1

( ) h ! h t f !
i i 1 2
, + +
1200 & 0 % , 0 , 0
0 0
t i
( )
o
t f ! ,
0 1


( ) 1200 , 0 f

( )
+ 3 12
10 +1 1200 10 2089 . 2


))96 . 3
( ) h ! h t f !
1 0 0 2
, + +
( ) ( ) 230 ))96 . 3 1200 , 230 0 + + f

( ) 06 . 108 , 230 f
( )
+ 3 12
10 +1 06 . 108 10 2089 . 2

The Runge Kutta method
019)6) . 0
h ! !
,
_

+ +
2 1 0 1
2
1
2
1


( ) ( ) 230 019)6) . 0
2
1
))96 . 3
2
1
1200
,
_

+ +

( )230 2902 . 2 1200 +
18 . 8)) K
K 18 . 8)) , 230 230 0 , 1
1 0 1
+ + h t t i
( )
1 1 1
, t f !

( ) 18 . 8)) , 230 f

( )
+ 3 12
10 +1 18 . 8)) 10 2089 . 2


*++86 . 0
( ) h ! h t f !
1 1 1 2
, + +
( ) ( ) 230 *++86 . 0 18 . 8)) , 230 230 + + f

( ) +9 . )81 , 3+0 f

( )
+ 3 12
10 +1 +9 . )81 10 2089 . 2


20208 . 0
h ! !
,
_

+ +
2 1 1 2
2
1
2
1


( ) ( ) 230 20208 . 0
2
1
*++86 . 0
2
1
18 . 8))
,
_

+ +

( )230 26)*+ . 0 18 . 8)) +
29 . )+3 K
( ) 29 . )+3 3+0
2
K
The results from 'eun,s method are com$ared "ith e0act results in <igure 2.
The e0act solution of the ordinary differential equation is given y the solution of a non-
linear equation as
( ) 62+2 . 2 10 22089 . 0 00***** . 0 tan +)16 . 1
*00
*00
ln 62)6* . 0
* 1

+

The solution to this nonlinear equation at 3+0 t s is


)9 . 839 & 3+0 %
K
The Runge Kutta method
-400
0
400
800
1200
0 100 200 300 400 500
Time, t%sec&
T
e
m
$
e
r
a
t
u
r
e
,
%
%
K
&
#0act
h ?120
h ?230
h ?3+0
Figure 2 'eun,s method results for different ste$ si=es.
@sing a smaller ste$ si=e "ould increase the accuracy of the result as given in Tale 1 and
<igure * elo".
Table 1 #ffect of ste$ si=e for 'eun,s method
1te$ si=e,
h
( ) 3+0
t
A
t

3+0
230
120
80
*0
-
*6*.+9
)+3.29
8)1.*)
836.61
83+.21
1031.3
8*.*03
-*.9982
-2.*308
-
0.8*216
180.+2
6.99)8
0.)+*1*
0.*813)
0.06982)
-400
-200
0
200
400
600
800
0 100 200 300 400 500
1te$ si=e, h
T
e
m
$
e
r
a
t
u
r
e
,
%
%
3
+
0
&
Figure 3 #ffect of ste$ si=e in 'eun,s method.
The Runge Kutta method
!n Tale 2, #uler,s method and the Runge-Kutta 2nd order method results are sho"n as a
function of ste$ si=e,
Table 2 Bom$arison of #uler and the Runge-Kutta methods
1te$ si=e,
h
& 3+0 %
#uler 'eun ;id$oint Ralston
3+0
230
120
80
*0
-6+9.+3
110.*2
)38.99
813.69
8*2.99
-*6*.+9
)+3.29
8)1.*)
836.61
83+.21
120+.3
698.+9
860.20
8)3.+)
836.02
336.9+
860.01
889.91
8)2.2)
83+.81
"hile in <igure 3, the com$arison is sho"n over the range of time.
500
600
700
800
900
1000
1100
1200
0 100 200 300 400 500 600
Time, t %sec&
T
e
m
$
e
r
a
t
u
r
e
,
/nalytical
Ralston
;id$oint
#uler
'eun
C
%
K
&
Figure 4 Bom$arison of #uler and Runge Kutta methods "ith e0act
results over time.
o! do these three methods "ompare !ith results obtained i# !e #ound
( ) y x f ,

dire"tl$?
Of course, "e 2no" that since "e are including the first three terms in the series, if the
solution is a $olynomial of order t"o or less %that is, quadratic, linear or constant&, any of the
three methods are e0act. Dut for any other case the results "ill e different.
4et us ta2e the e0am$le of
( ) ) 0 , *
2


y y e
dx
dy
x
.
The Runge Kutta method
!f "e directly find
( ) y x f ,
, the first three terms of the Taylor series gives
( ) ( )
2
1
,
- 2
1
, h y x f h y x f y y
i i i i i i
+ +
+
"here
( ) y e y x f
x
* ,
2


( ) y e y x f
x
6 ) ,
2
+

<or a ste$ si=e of 2 . 0 h , using 'eun,s method, "e find
( ) 06*0 . 1 8 . 0 y
The e0act solution
( )
x x
e e x y
* 2
3

+
gives
( )
( ) ( ) 8 . 0 * 8 . 0 2
3 8 . 0

+ e e y
682*6 . 0
Then the asolute relative true error is
100
682*6 . 0
06*0 . 1 682*6 . 0


t
A )91 . 1*
<or the same $rolem, the results from #uler,s method and the three Runge-Kutta methods
are given in Tale *.
Table 3 Bom$arison of #uler,s and Runge-Kutta 2nd order methods
y%0.8&
#0act #uler Eirect 2nd 'eun ;id$oint Ralston
Falue
0.682*
6
0.36)
)
1.06*0
1.101
2
1.0693 1.0663
t


A
3+.)1
3
1*.)91
13.32
*
13.026 13.2*8
%ppendix %
o! do !e get the 2nd order Runge-Kutta method e&uations?
7e "rote the 2nd order Runge-Kutta equations "ithout $roof to solve
( ) y x f
dx
dy
,
,
( )
0
0 y y
%/.1&
as
( ) h ! a ! a y y
i i 2 2 1 1 1
+ +
+
%/.2&
"here
( )
i i
y x f ! ,
1

%/.*a&
( ) h ! q y h p x f !
i i 1 11 1 2
, + +
%/.*&
and
1
2 1
+ a a
2
1
2 2
p a
The Runge Kutta method
2
1
11 2
q a
%/.3&
The advantage of using 2nd order Runge-Kutta method equations is ased on not having to
find the derivative of
( ) y x f ,
symolically in the ordinary differential equation
1o ho" do "e get the aove three #quations %/.3&( This is the question that is ans"ered in
this /$$endi0.
7riting out the first three terms of Taylor series are
( )
* 2
2
2
1
- 2
1
h & h
dx
y d
h
dx
dy
y y
i i
i i y x
y x
i i
+ + +
+ %/.)&
"here
i i
x x h
+1
1ince
( ) y x f
dx
dy
,
"e can re"rite the Taylor series as
( ) ( ) ( )
* 2
1
,
- 2
1
, h & h y x f h y x f y y
i i i i i i
+ + +
+
%/.8&
5o"
( )
( ) ( )
dx
dy
y
y x f
x
y x f
y x f


, ,
,
. %/.9&
'ence
( ) ( )
* 2
, , ,
1
- 2
1
, h & h
dx
dy
y
f
x
f
h y x f y y
i i i i i i
y x y x y x
i i i i
+

,
_

+ +
+

( ) ( ) ( )
* 2
,
2
,
,
2
1
2
1
, h & h y x f
y
f
h
x
f
h y x f y
i i
y x y x
i i i
i i i i
+

+ +

%/.+&
5o" the term used in the Runge-Kutta 2nd order method for
2
! can e "ritten as a Taylor
series of t"o variales "ith the first three terms as
( ) h ! q y h p x f !
i i 1 11 1 2
, + +

( ) ( )
2
,
1 11
,
1
, h &
y
f
h ! q
x
f
h p y x f
i i i i y x y x
i i
+

+

%/.6&
'ence
( )h ! a ! a y y
i i 2 2 1 1 1
+ +
+

( ) ( ) ( ) h h &
y
f
h ! q
x
f
h p y x f a y x f a y
i i i i y x y x
i i i i i

,
_

'

+ + +
2
,
1 11
,
1 2 1
, ,

( ) ( ) ( ) ( )
*
,
2
11 2
,
2
1 2 2 1
, , h &
y
f
h y x f q a
x
f
h p a y x hf a a y
i i i i y x
i i
y x
i i i
+

+ + +

%/.10&
#quating the terms in #quation %/.+& and #quation %/.10&, "e get
1
2 1
+a a
The Runge Kutta method
2
1
1 2
p a
2
1
11 2
q a

Das könnte Ihnen auch gefallen