You are on page 1of 11

NUMERICAL SOLUTION TO ORDINARY DIFFERENTIAL EQUATIONS

Definition. An nth order Ordinary Differential Equation (ODE) may be written in the form
dy d 2 y
dn y
F x , y , , 2 , , n =1(1)
dx d x
dx

Equation (1) is termed nth order because the highest ordered derivative appearing in the equation is of order n,
and ordinary because only total derivatives are present (no partial derivatives, therefore there is only one
independent variable).
A function y (x) that satisfies Equation (1) is said to be a solution of the equation. By a solution for a given
x, y ,

dy d 2 y
dn y
, 2 ,, n
dx d x
dx

are evaluated and substituted to Equation (1). To determine a unique solution, it is

necessary to supply additional information, namely values of


value (or values) of

y ( x) and/or of its derivatives at some specific

x . For an nth order ODE, n even conditions are normally sufficient to yiels a unique

solution.
Example. Consider the 1st order ODE
dy
= y (2)
dx
The analytical solution of this is
dy
y = dx ln y=x + ln c y=ce x(3)
This is a family of solution for different values of c . If the condition
unique value of c (c=1) giving the unique solution

y ( 0 )=1 is given, we arrive at a

y=e x which is the middle curve shows.

10
8
6
4
2

y=2e^x
y=e^x
y=(1/2)e*x

0
-1 -0.5 0 0.5 1 1.5 2 2.5 3
-2

Any nth order ODE may be written as a system of n 1st order ODEs by defining as a system of n1 new
variables. For example, the second order ODE Bessel Function
2
dy
2d y
2
2
x
+ x + ( x p ) y =0
2
dx
dx
Letting z=dy /dx , we can rewrite the equation as a pair of 1st order ODEs
dy
2 dz
2
2
z=0x
+ xz + ( x p ) y=0
dx
dx

Since any higher order ODE (or system of such ODEs) can be rewritten in a similar fashion, only the numerical
solution of the 1st order ODE will be considered.

FIRST ORDER ORDINARY DIFFERENTIAL EQUATIONS


F ( x , y , dy /dx )=1 or alternatively dy /dx=( x , y ) . Our task is to find a unique solution

General form.

y ( x ) which satisfies both the equation and one specified initial condition. Numerically the solution

y (x )

takes the form of a table


x0

y0

x1

y1

x2

y2

x3

y3

x4

y4

.
.
.

.
.
.

xn

yn

Numerical solution of the DE subject to the initial condition

y ( x0 ) = y 0

in the interval

x0

to

xn

Notation: [ a , b ] = interval in the indeval in the independent variable ober which n solution is desired.
n= number of subintervals in [ a , b ]
h= step size (ba)/n

x i=x o +ih, i=1,2,3, ,n

= specified values of the independent variable

y ( x )= solution or object function

x at which

y ( x ) is computed

y ( xi ) =

true value of

xi

y ( x) at

y i= computed approximation of

y ( x) at

f ( x i , y ( x i ) ) = true value of dy /dx


f ( x i , y i ) =

(usually unknown)

at

xi

xi

(usually unknown)

computed approximation of dy /dx

i= y i y ( x i )=

at

xi

discretization or truncation error

TWO APPROACHES TO THE NUMERICAL SOLUTION OF FIRST ORDER ODE


1. Direct or indirect use of Taylor Series Expansion solution or object function y ( x )
2. Use of open or closed integration formula.
Whatever the approach, the various numerical procedures can be classified into two groups: a) one stop method
y i1
and b) multistep method. One step method permits calculation of
given the ODE and information at
xi

only. Multistep method requires, in addition, values of

values of

xj

yj

and/or

outside the integration interval under consideration,

fj

[ x i , x i+1 ]

at other (usually several)


. Two disadvantages of multistep

methods are: a) it is difficult to get started, and b) it is difficult to change step size once the calculation is
underway. However, the multistep methods are require less computation, compared with one-step method to
produce results of comparable accuracy.
NUMERICAL SOLUTION OF FIRST ORDER ODEs BY DIRECT USE OF THE TAYLOR SERIES
EXPANSION OF THE SOLUTION FUNCTION y (x) (TSE)
Given :

dy
=f ( x , y ) withinitial solution y ( x 0 )= y 0 , one step method of approximating the
dx

solution isused for .


TAYLOR EXPANSION : y ( x i +1) = y ( x i+ h )
y ( x i ) + hf ( xi , y ( x i ) ) +

Given ODE :

h2 '
h3
hn
hn +1 ( n)
f ( x i , y ( xi ) ) + f ' ' ( x i , y ( x i) ) ++ f ( n1 ) ( xi , y ( x i ) ) +
f ( x i , y ( x i ) ) where x i x i +1
2!
3!
n!
( n+ 1 ) !

dy
=f ( x , y )=f
dx

df f f y f f
'
= +
= +
f =f
dx x y x x y
d2 f f ' d f f
= =
+
f
d x 2 x dx x y

f f
f f
+
f +
+
f f
x x y
y x y

) (

EXAMPLES DIRECT USE OF TSE OF


1.

y (x )

dy
2
=f ( x , y )=x with y ( x 0) = y 0
dx
f ( x , y ) =x2 f ' ( x , y )=2 x f ' ' ( x , y )=2 f ' ' ' ( x , y ) =0
y ( xi +1 )= y ( x i ) +hf ( x i , y ( x i ) ) +
y ( x i ) + h x 2i +

h2 '
h3
f ( x i , y ( x i ) )+ f ' ' ( xi , y ( x i ) )
2!
3!

h2
h3
( 2 x i ) + ( 2 ) +0
2!
3!

y ( x i ) + h x 2i +h2 xi +

h3
(a)
3

Hence starting from the given initial condition, we generate

y ( xi )

values at

x i , i=1,2,3, .

, by

repeated use of Equation (a). Note that since the 3rd and higher ordered derivatives are zero, the values given
Equation (a) are exact, assuming no round-off errors.
h3
y ( x1 ) = y ( x0 ) + h x 20 +h 2 x 0+
3
y ( x2 ) = y ( x1 ) + h x 21 +h2 x1 +

h3
3

y ( x3 ) = y ( x2 ) + h x 22 +h2 x 2+

h3
3

2.

dy
=f ( x , y )=2 y with y ( x 0 )= y 0
dx
f ( x , y ) =2 y f ' ( x , y )=
f ' ' ( x , y )=
f ' ' ' ( x , y )=

'

f f
+
f =0+2 ( 2 y )=4 y =f '
x y

'

f f
+
f =0+4 ( 2 y ) =8 y=f ' '
x y

f'' f ''
+
f =0+8 ( 2 y )=16 y=f ' ' '
x y

y ( xi +1 )= y ( x i ) +hf ( x i , y ( x i ) ) +

h2 '
h3
h4
f ( x i , y ( x i ) ) + f ' ' ( x i , y ( x i ) ) + f '' ' ( x i , y ( xi ) )
2!
3!
4!

4
Truncating thw series after the fifth term (or retaining the term through h , and substituting the

expressions for the derivatives, we obtain


( 2h )2 ( 2h )3 ( 2h )4
h2
h3
h4
y ( xi +1 )= y i +h ( 2 y i ) + ( 4 y i) + ( 8 y i ) + ( 16 y i )= y i 1+2 h+
+
+
2!
3!
4!
2!
3!
4!

Note the shift in the notation from

xi

to

yi

(2 h )2 ( 2 h )3 ( 2 h ) 4

=1+2
h+
+
+
, and if we designate
2!
3!
4!

the calculated values given in the previous equation are approximations to the true value of
y ( xi +1 ) ,i=1,2,3 .
, brought about by truncating the series. Applying the above equation,
y 1= y 0
y 2= y 1
y 3= y 2

and

THE EULER METHOD


Except for a few problems, getting the higher
order derivatives of the function f (x , y ) can
be very complicated. This makes the direct use of
TSE of y (x) to solve 1st order ODEs of little
practical importance, if we insist on retaining
p
terms of the series through h , p 2 . However,
if we drop all terms except the first two, we
obtain a simple procedure called the EULER
Method:
y ( xi +1 )= y i +h f ( x i , y i)
Euler Method has a very simple graphical
interpretation as indicated below. It is easy to see
if Euler Method is applied repeatedly across
several intervals in polygon segment with sides of slopes

f ( x i , y i ) , i=0,1,2, .

A fundamental concept in assessing the accuracy


of the method is its order. The order is defined in
terms of the local discretization error obtained
when the method is applied to problems with
smooth solutions. A method is said to be of order
order p if the number C such that

|d i|C h p+1

where

di

is the local

discretization error incurred in integrating over


xi
x i+1
the interval
to
. The above
inequality can be abbreviated using the Onotation
d i=O ( h p +1 )
Recall that the Euler method was
obtained by dropping the terms of TSE
2
of y ( x) in O ( h ) , which means
that the local discretization error
2
for the method is O ( h ) . Assuming stability of the ODE, the global discretization error in
applying Euler method over
method is of order 1.

steps is

nO ( h2 )=O ( h 1) . Hence we say that Euler

Example: Euler Method

di
Given ODE : L + Ri=E , at i (t=0 )=0
dt
Required:

L=?

at 1 sec, 2 sec, 3 sec and 4 sec after switch is


closed using h= 0.1 sec, 0.01 sec, 0.001 sec

The analytical solution subject to initial condition is

i=

E
( 1eRt / L) . We will compare
R

results of the numerical method from Euler method for the different step sizes wit(h this
analytical solution. The given ODE is rewrittem in the form suitable for the Euler
method:
di ERi
=
=f ( t ,i )
dt
L
Then the Euler formulais i j+1=i j+ hf ( t j , i j ) =i j +h
For h=1 sec ,i 1=i 0 +1

ERi j
102 i j
=i j + h
L
5

102 i 0
102 0
=0+
=2.0 ; i2 =3.2 sec
5
5

Summary of Results
Analyti
Time
cal
in
h=1
solutio
Sec
n
0
0
0

Error

h=0.1

Error

h=0.0
1

Error

h=0.0
01

Error

1.6484
0

2.000
0

0.351
60

1.675
83

0.027
43

1.651
06

0.002
66

1.648
46

2.7533
6

3.200
0

0.446
64

2.789
98

0.036
62

2.766
10

0.012
74

2.753
18

3.4940
3

3.920
0

0.425
97

3.530
70

0.036
67

3.497
57

0.003
54

3.493
64

3.9905
2

4.352
0

0.361
48

4.023
16

0.032
64

3.993
65

0.003
13

3.990
02

0.0000
6
0.0001
8
0.0003
9
0.0005
0

RUNGE-KUTTA METHODS
A. Important properties of the Runge-Kutta Methods
1. They are one-step methods
2. They require the evaluation of f (x , y ) , and none of its derivatives
3. They result with accuracies equivalent to TSE of
through

f ( x)

retaining terms

h , h ,h , etc. depending on the order of the method

B. General Form of the R-K Method


y i+1= yi +h ( x i , y i , h ) where h=step x i +1x i
( xi , y i , h ) =incrementfunction, which is simply a suitable chosen approximation

find f ( x , y ) on theinterval x i x x i+1


dy
=f (x , y)
dx

C. 2nd order R-K Methods. Given ODE:


Let

( xi , y i , h )

evaluations

be the weighted average of the two first order derivative


k 1k 2

x i x xi +1

on the interval

, that is,

( xi , y i , h ) =a k 1+ b k 2 (2)
Substituting (2) in the general form then yields
y i+1= yi +h ( a k 1 +b k 2 ) (3)
Now let
k 1=f ( x i , y i ) ( 4)
k 2=f ( x i+ ph , y i +q k 1) (5)
1
1
a= , b= , p=1, q=1
2
2

1. The improved Eulers Method:


y i+1= yi +h ( a k 1 +b k 2 ) = y i+ h

( 12 k + 12 k )= y + h2 (k +k )
1

k 1=f ( x i , y i )
k 2=f ( x i+ h , yi + k 1 )
a=0, b=1, p=q=

2. Modified Eulers method

1
y i+1= yi +h ( a k 1 +b k 2 ) = y i+ h 0+ k 2 = y i+ h k 2
2

k 1=f ( x i , y i )
k
h
k 2=f x i + , y i + 1
2
2

D. 3rd Order R-K Method


General Formula:
h
y i+1= yi + ( k 1 +4 k 2 +k 3 )
6
k 1=f ( x i , y i )
k
h
k 2=f x i + , y i + 1
2
2

k 3 =f ( x i+ h , y ik 1 +2 k 2 )
E. 4th Order R-K Method

1
2

General Formula:
h
y i+1= yi + ( k 1 +2 k 2 +2 k 3 +k 4 )
6
k 1=f ( x i , y i )
k
h
k 2=f x i + , y i + 1
2
2

(
)
k
h
k =f ( x + , y + )
2
2
2

k 4=f ( xi +h , y i +k 3 )
SIMULTANEOUS SOLUTION TO SYSTEM OF 1ST ORDER ODEs
Problem: Find the solution of the system of ODE in the form
( x , y , z )dz
dy
=f
=f ( x , y , z )
dx
dx

Say we use 3rd order RKM:


h
y i+1= yi + ( k 1 +4 k 2 +k 3 )
6
k 1=f ( x i , y i , z i )
k
r
h
k 2=f x i + , y i + 1 , z i+ 1
2
2
2

k 3 =f ( x i+ h , y ik 1 +2 k 2 , z ir 1+ 2r 2 )
h
z i+1=z i + ( r 1 + 4 r 2 +r 3 )
6
r 1=f ( xi , y i , z i )
k
r
h
r 2=f x i + , y i+ 1 , zi + 1
2
2
2

r 3=f ( x i+ h , y ik 1 +2 k 2 , z ir 1 +2 r 2 )

HIGHER ORDERED ODEs


Say we have a 4th order ODE:

d4 y
d3 y
d2 y
dy
4
+
4
xy
+
4
x
+2 y + 4 y =0
4
3
2
dx
dx
dx
dx
Method: Reduction of order
Let
2
3
dy
dp d y
dw d y
p= ; w= = 2 ; z= = 3
dx
dx d x
dx d x
Substitution:
DE 1 :

dz
=4 xyz4 xw2 xp4 y 4
dx

DE 2 :

dy
=p
dx

DE 3 :

dp
=w
dx

DE 2 :

dw
=z
dx

Then solve as in simultaneous 1st order ODEs

You might also like