You are on page 1of 5

NUMERICAL METHODS FOR ORDINARY DIFFERENTIAL

EQUATIONS
Euler’s Method
-To approximate the solution of the initial value problem
y’ = f( t , y ) with y(a) = yo over [ a , b ] by computing

y(k+1) = y(k) + h f( tk , yk)

h = t 1 - t0 , k =0 , 1, 2, …..( n-1)

EXAMPLE:
Use Euler’s method to solve the IVP
t− y
y'= on [ 0 , 3 ] with y ( 0 )=1
2

Compare solutions for h = 1 , ½ , ¼, and 1/8


Exact Solution: y ( t ) =2 e−t / 2−2+t

For the step size h = 1/4


y 1= y 0+h ( t 0−2 y 0 )
1 0−1
y 1=1+( )(
2 )
=0.875
2

t 1− y 1
y 2= y 1+ h (
2 )
y 2=0.875+ ( 12 )( 0.25−0.875
2 )=0.796875
t 2− y 2
y 3= y 2+h (
2 )

y 3=0.796875+ ( 12 )( 0.5−0.796875
2 )=0.759766

y 12=1.440573+ ( 12 )( 2.75−1.440573
2 )=1.60425 2
Runge-Kutta Method ( of order 4)
- RK4

To approximate the solution of the initial value problem


y’ = f(t) with y(a) = y0 over [ a , b ] by using the formula

y(k+1) = y(k) + h/6 ( f1 + 2 f2 + 2 f3 + f4 )

where: f1 = f ( tk , yk )

f2 = f ( tk+ h/2 , yk + h/2 f1)


f3 = f ( tk + h/2 , yk + h/2 f2 )
f4 = f ( tk + h , yk + h f3 )
h = t 1 - t0 , k =0 , 1, 2, …..( n-1)
EXAMPLE :
Use RK4 to solve the IVP
y’ = ( t –y) /2 on [ 0 , 3 ] with y(0) = 1 , h ¼
For step size h = 0.25
y(k+1) = y(k) + h/6 ( f1 + 2 f2 + 2 f3 + f4 )

f1 = ( t0 – y0 )/2 = ( 0.0 – 1.0 ) /2 = -0.5

((t 0+h /2))−(( y 0+(h/2)f 1))


f 2=
2

f2 = (( 0 + 0.25/2)) - ( ( 1 + ( 0.25/2) ( -0.5))/2 = -0.40625

f3 = f ( tk + h/2 , yk + h/2 f2 )

f3 = ( 0 + 0.125 /2) – ( 1 + ( 0.25/2)( -0.40625))/2 = -0.4121094

f4 = f ( tk + h , yk + h f3 )

f4 = (( 0 +0.25 – ( 1 + ( 0.25) (-0.4121094)))/2 = -0.3234863

y1 = y(0) + h/6 ( f1 + 2 f2 + 2 f3 + f4 ) = 0.8974915


Lab Activity 7 ODE : EULER and RK4

You might also like