Nothing Special   »   [go: up one dir, main page]

09 - Lecture Note 09 - Numerical Solution ODE

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 8

Lecture Note 9

Ordinary Differential Equation (ODE)


9.1. Solution of ODE using Runge-Kutta et!od " first order
Differentiation is generally e#$ressed as follo%s &
) y , x ( f ) x ( ' y
dx
dy

as %ell as
) y , t ( f ) t ( ' y
dt
dy

(9-
1)
'f dx = h( t!en eq. (9-1) can )e odified as
1
*( ) . ( ( )
n n n
y y dx y x y h f x y
+
+ +
(9-+)
Eq. (9-+) %as considered to )e t!e first order Runge-Kutta. Solution can )e o)tained
only if t!e )oundary condition (for x) or t!e initial condition (for t) is gi,en. -!e
increent of x (i.e. x = h) or t!e increent of tie or tie ste$ (i.e. t = h) can )e
set )ased on t!e nature of t!e $ro)le( %!eter it includes !ig!er accuracy or not.
9.1. Solution of ODE using Runge-Kutta et!od " !ig!er order
-!e second order of Runge-Kutta et!od %as de,elo$ed fro t!e first order.
.asically( t!e second order is su)/ect to t%o corrections( %!ereas t!e first order !as
only one eleent of correction. -!e second orde Runge-Kuta %as e#$ressed as &
y
n+1
= y
n
+ ak
1
+ bk
2
(9-0)
%!ere &
k
1
= hf (x
n
, y
n
)
k
2
= hf (x
n
+ h, y
n
+ k
1
)
k
2
= hf (x
n
+h, y
n
+ k
1
)
h = x
n+1
- x
n

1lgorit! of second order Runge-Kutta et!od &
o 2or equation &
y = f(x, y) , y(x
o
) = y
o
a = b = , = = 1
o 3alculate y
n
u$ to y(x
o
+nh) for constant h and n = 0, 1, 2, using follo%ing
equations &
y
n+1
= y
n
+ (k
1
+ k
2
) %it!
k
1
= hf (x
n
, y
n
)
Lecture Note - Dr.'r. Lili4 E4o 5idodo( 6S
9-1
k
2
= hf (x
n
+h, y
n
+k
1
)
1lgoritt! of fourt! order Runge-Kutta et!od &
o 2or equation &
y = f(x, y) , y(x
o
) = y
o
o 3alculate y
n
u$ to y(x
o
+nh) for constant h and n = 0, 1, 2, using follo%ing
equations &
y
n+1
= y
n
+ 1/6 (k
1
+ 2k
2
+ 2k

+ k
!
) %it! & (9-7)
k
1
= hf (x
n
, y
n
)
k
2
= hf (x
n
+ h, y
n
+ k
1
)
k

= hf (x
n
+ h, y
n
+ k
2
)
k
!
= hf (x
n
+h, y
n
+k

)
E#a$le 1& second order Runge-Kutta &
8i,en &
y
x ) y , x ( f ' y
1

and y(0) = 1
8i,e & solution %it!in inter,al x = 0 to x = 1 %it! h = 0.1
Solution %as gi,en in t!e -a)le 9-1 and corres$ondingly de$icted )y 2igure 9.1.
-a)le 9-1& Solution of e#a$le 1
# y
n
41 4+ 9y y
n:1
; 1 -;.1;;; -;.1111 -;.1;<= ;.>977
;.1 ;.>977 -;.1;1> -;.11=+ -;.1;9; ;.?><<
;.+ ;.?><< -;.1;?0 -;.1+?< -;.11?7 ;.==>1
;.0 ;.==>1 -;.119? -;.1<+7 -;.10=; ;.<0+1
;.7 ;.<0+1 -;.17?9 -;.++;0 -;.1>71 ;.07?9
;.< ;.07?9 -;.+0?7 -;.><<1 -;.<7=+ -;.19>0
;.= -;.19>0 ;.<=7+ -;.+100 ;.1?<7 -;.;++9
;.? -;.;++9 7.70>? ;.;7?7 +.+70; +.++;1
;.> +.++;1 ;.;0<; ;.;0<? ;.;0<0 +.+<<7
;.9 +.+<<7 ;.;7<? ;.;7=< ;.;7=1 +.0;1<
1 +.0;1< ;.;<== ;.;<?= ;.;<?1 +.0<>=
Lecture Note - Dr.'r. Lili4 E4o 5idodo( 6S
9-+
2igure 9.1& Solution of e#a$le 1
9.0. Solution of ODE using @redictor - 3orrector et!od
@redictor-corrector et!od %as considered to )e li4ely Runge-Kutta %it! indefinite
correction. -!e nu)er of correction can )e set de$ending on t!e accuracy t!at %ill
)e needed. -!e $redictor-corrector et!od %as )ased on t!e $olynoial
inter$olation %it!in inter,al )et%een x
n+1
and x
n
t!at %as e#$ressed as &
[ ] ...... , 2 , 1 n ) y , x ( f ) y , x ( f
2
h
y y
1 n 1 n n n n 1 n
+ +
+ + +

(9-<)
x & inde$endent ,aria)le
y & de$endent ,aria)le
h & x
n+1
- x
n
Eq. (9-<) is t!e i$licit for for y
n+1
( since y
n+1
a$$ears to )e an arguent at rig!t
!and side. 'f f(x,y) is non-linear( t!en eq. (9-<) can not )e closely sol,ed.
1ccordingly( y
n+1
%ill )e iterati,ely sol,ed. .y introducing t!e ,alue of x
n
( t!e first
estiated ,alue
( ) 0
1 n
y
+
on
1 n
y
+
%ill )e o)tained )ased on t!e first order Runge-Kutta
et!od as &
Lecture Note - Dr.'r. Lili4 E4o 5idodo( 6S
9-0
-0.5
0
0.5
1
1.5
2
2.5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
x
n
y
n
( )
) y , x ( hf y y
n n n
0
1 n
+
+
(9-
=)
Su)sequenly using
( )
) y , x ( f
0
1 n 1 n + +
t!e first iteration %ill )e $erfored )y eans
su)stitution into t!e eq. (9-<)( t!en %ill )e o)tained follo%ing equation &
( ) ( )
[ ] ) y , x ( f ) y , x ( f
2
h
y y
0
1 n 1 n n n n
1
1 n + + +
+ + (9-
?)
Second iteration %ill )e o)tained )y eans of su)stitution of
( )
) y , x ( f
1
1 n 1 n + +
into eq.
(9-?). 'n general t!e iteration %ill )e resulted in &
( ) ( )
[ ] ...... , 2 , 1 k ) y , x ( f ) y , x ( f
2
h
y y
1 k
1 n 1 n n n n
k
1 n
+ +

+ + +
(9-
>)
-!e iteration can only )e sto$ed if t!e le,el of accuracy !as already )een ac!ie,ed.
1lgorit! of @redictor " 3orrector &
Ste$ 1 & $rediction ste$ (o"ter iteration)
2or n starting fro 1 and for equation y' = f(x,y), y(x
0
) = y
0

%it! h = x
n+1
- x
n
and x
n
= x
0
+ nh(
calculate
( ) 0
1 n
y
+
using eq. (9-=).
Ste$ + & correction ste$ (inner iteration)
2or k = 1,2, calculate
( ) k
1 n
y
+
using eq. (9-9)( until
follo%ing le,el of accuration is ac!ie,ed &
<

+ +
) k (
1 n
) 1 k (
1 n
) k (
1 n
y
y y
Re$eat ste$ 1 for n = n + 1.
Soe of $araeters t!at !a,e to )e deterined or gi,en in order to sol,e t!e
nuerical integration )ased on t!e $redictor-corrector according t!e algorit! a)o,e
are as follo%s &
- -!e ,alue of n (nu)er of outer iteration)
- -!e ,alue of k (nu)er of inner iteration)
Eq. (9-=) is e#$licit t!at is called as t!e t!e $redictor( %!ereas eq. (9-<) is i$licit
and called as t!e t!e corrector. 'f )ot! of t!e is siultaneously used( t!en t!e
corres$onding et!od can )e called as t!e $redictor-corrector. -!e result fro t!e
correction equation of ste$ %ill al%ays )e ore accurate t!an t!e $rediction.
E#a$le +& i$leentation of @redictor " corrector et!od
Lecture Note - Dr.'r. Lili4 E4o 5idodo( 6S
9-7
8i,en &
y
x ) y , x ( f ' y
1

and y(0) = 1
8i,e & solution %it!in inter,al fro x = 0 to x = 0.2 %it! h = 0.1
1ns%er & y'''(0) -2( t!en t!e error A -(h

/12)y''' 0.0002
Ste$ 1 & for n = 1( fro eq. (9-=) %ill )e o)tained
( )
# . 0 y
0
1

Ste$ + & fro eq. (9->) %ill )e resulted in
( )
$##! . 0 y
1
1
and
( )
$##! . 0 y
2
1

Since t!e ,alue of
( ) ( )
$##! . 0 y y
2
1
1
1
( t!en t!e inner iteration %as
sto$ed and results in t!e ,alue of y
1
= 0.$##! t!at can )e used to
co$ute its deri,ate as follo%s &
( ) 011$ . 1
y
1
x y , x f y
1
1 1 1
'
1

on x
1
= x
0
+nh = 0.1
Ste$ 1 & for n = 2 fro eq. (9-=) %ill )e o)tained

( )
%#$2 . 0 ) 011$ . 01 ( 1 . 0 $##! . 0 y
0
2
+
Ste$ +& fro eq. (9-=) %ill )e o)tained
( )
%#62 . 0
%#$2 . 0
1
2 . 0 011$ . 1 0& . 0 $##! . 0 y
1
2

1
]
1

,
_

+ +
( )
%#60 . 0
%#62 . 0
1
2 . 0 011$ . 1 0& . 0 $##! . 0 y
2
2

1
]
1

,
_

+ +

( )
%#60 . 0 y

2

Since
( ) ( )
%#60 . 0 y y

2
2
2
( t!en t!e iteration %as sto$ed and t!e ,alue
of y
2
= 0.%#60 can )e used to calculate its deri,ate( i.e &

0&62 . 1
y
1
x ) y , x ( f y
2
2 2 2
'
2

on x
2
= x
0
+ nh = 0.2
Le,el of accuracy of ODE solution using $redictor-corrector %as indicated )y t!e
nu)er of iteration( es$ecially t!e inner iteration
9.7. Solution of SODE using Runge-Kutta et!od
Runge-Kutta et!od for single ODE can )e de,elo$ed for solution of syste of
siultaneous ODE (SODE). 2ollo%ing is t!e e#a$le of de,elo$ent of Runge-
Kutta for second order SODE.
( )
( ) y , x , t ' y
dt
dy
y , x , t f x
dt
dx
'
t
'
t



(9-9)
f and ' are function of t( x and y t!at is usually gi,en. 't can su)sequently )e defined
as follo%s &
Lecture Note - Dr.'r. Lili4 E4o 5idodo( 6S
9-<

) t ( y y
) t ( x x
t t h
n n
n n
n 1 n


+
(9-
1;)
%it! follo%ing $araeters of t!e fourt! order Runge-Kutta &
( )
( )
n n n 1
n n n 1
y , x , t ' h (
y , x , t f h k

(9-
11)

,
_

+ + +

,
_

+ + +
2
(
y ,
2
k
x ,
2
h
t ' h (
2
(
y ,
2
k
x ,
2
h
t f h k
1
n
1
n n 2
1
n
1
n n 2
(9-
1+)

,
_

+ + +

,
_

+ + +
2
(
y ,
2
k
x ,
2
h
t ' h (
2
(
y ,
2
k
x ,
2
h
t f h k
2
n
2
n n
2
n
2
n n
(9-10)
( )
( )
n n n !
n n n !
( y , k x , h t ' h (
( y , k x , h t f h k
+ + +
+ + +
(9-17)
-!e ,alue of x and y on
1 n
t
+
is &
( )
( )
! 2 1 n 1 n
! 2 1 n 1 n
( ( 2 ( 2 (
6
1
y y
k k 2 k 2 k
6
1
x x
+ + + +
+ + + +
+
+
(9-1<)
E#a$le 0& Solution of SODE using Runge-Kutta et!od&
8i,en follo%ing diffusion equation. ) and t are res$ecti,ely ,aria)le for
concentration and tie.

)'' + 2 t )' * 0.& ) = 0 (9-
1=)
Solution inter,al fro t = 0 to t = 0.& %it! )oundary condition ) = 1 and )' = 0.
1ns%er &
Lecture Note - Dr.'r. Lili4 E4o 5idodo( 6S
9-=
-ie ste$ or h %as set to )e 0.1. -!e ne#t ste$ is to odify eq. (9-1=) to )ecoe first
order )y eans of setting& x = )( y A )', t!en eq. (9-1=) can )e odified to )ecoe a
$air of follo%ing equations &
ty 2 x & . 0 ' y
y ' x


(9-1?)
5it! )oundary condition x = 1 and y = 0 on t = 0. 1ccording to eq (9-9)( t!e f and '
can )e defined as &
( )
( ) ty 2 x & . 0 y , x , t ' y
y y , x , t f x
'
'



(9-1>)
2or first a$$roac! it %ill )e used t
0
= 0, x
0
= 1 and y
0
= 0. Su)sequently )y
su)stitution into eq. (9-1+) to eq. (9-17) %ill )e o)tained follo%ing quantities &

( )
( )
( ) ( ) ( ) [ ] 0!#12$ . 0 0!#$1! . 0 0 x 1 . 0 0 2 002!$$ . 0 1 & . 0 x 1 . 0 (
00!#$1 . 0 0!#$1! . 0 0 x 1 . 0 k
0!#$1! . 0
2
0!#%& . 0
0 x
2
1 . 0
0 2
2
002& . 0
1 & . 0 x 1 . 0 (
002!$$ . 0
2
0!#%& . 0
0 x 1 . 0 k
0!#%& . 0
2
0& . 0
0 x
2
1 . 0
0 2
2
0
1 & . 0 x 1 . 0 (
002& . 0
2
0& . 0
0 x 1 . 0 k
0& . 0 0 x 0 x 2 1 x & . 0 x 1 . 0 (
0 0 x 1 . 0 k
!
!

2
2
1
1
+ + +
+

1
]
1

,
_

+
,
_

+
,
_

+

,
_

1
]
1

,
_

+
,
_

+
,
_

+

,
_

+



-!at %ill gi,e t!e x and y at t!e ne#t ste$ &
0!#%0# . 0
6
0!#12$ . 0 0!#$1! . 0 x 2 0!#%& . 0 x 2 0& . 0
0 y
002!# . 1
6
00!#$1 . 0 002!$$ . 0 x 2 002& . 0 x 2 0
1 x
1
1

+ + +
+

+ + +
+
-!e ne#t result u$ to t!e fift! iteration %as gi,en in t!e follo%ing -a)le.
-a)el 9-+& 'teration Result
n = Iterasi 0 1 2 3 4 5
tn 0 0.1 0.2 0.3 0.4 0.5
xn 1 1.0025 1.0099 1.0219 1.0382 1.0582
Lecture Note - Dr.'r. Lili4 E4o 5idodo( 6S
9-?
yn 0 0.0497 0.0977 0.1424 0.1824 0.2167
k1 0 0.0050 0.0098 0.0142 0.0182 0.0217
l1 0.0500 0.0491 0.0466 0.0426 0.0373 0.0312
k2 0.0025 0.0074 0.0121 0.0164 0.0201 0.0232
l2 0.0498 0.0480 0.0447 0.0400 0.0343 0.0279
k3 0.0025 0.0074 0.0120 0.0162 0.0200 0.0231
l3 0.0498 0.0481 0.0448 0.0401 0.0345 0.0281
k4 0.0050 0.0098 0.0142 0.0183 0.0217 0.0245
l4 0.0491 0.0466 0.0425 0.0373 0.0312 0.0247
xn + 1 = C 1.0025 1.0099 1.0219 1.0382 1.0582 1.0813
yn + 1 = C 0.0497 0.0977 0.1424 0.1824 0.2167 0.2447
Lecture Note - Dr.'r. Lili4 E4o 5idodo( 6S
9->

You might also like