Вы находитесь на странице: 1из 15

CMME 1 : Numerical solution of ODE

1. Objectives
i)
ii)
iii)
iv)
v)

To learn how to solve ODE problem with different methods.


To study the effects of size of step size, h on the accuracy.
To investigate which method will provide a better accuracy.
To learn how to do calculations of different method in Microsoft Excel.
To generate of graphs of different methods in Microsoft Excel.

2. Introduction : The numerical methods for ODE


(a) Euler Method
y i+1= yi +hf ( x i , yi )

Calculation:
f ( t , y ) =1+

( yt ) y ( 1)=2

1+

( 21 )

3
y 0.5= y 0+ hf ( t 0 , y 0 )
2+ ( 0.5 ) ( 3 )

3.5
(b) Midpoint Method

Step 1 :

h
K 1=f ( xi , y i ) , y m = y i + K 1
2

Step 2 :

h
K 2=f x i + , y m , y i+1= y i+ h K 2
2

Calculation :

f ( t , y ) =1+

( yt ) y ( 1)=2

K 1=f ( t 0 , y 0 )=1+

( 12 )=3

h
0.5
y m= y 0 + K 1=2+
3=2.7 5
2
2

( )

h
2.7 5
K 2=f t 0 + , y m =1+
=3.2
2
1.2 5

) ( )

y 0.5= y 0+ h K 2=2+ ( 0.5 ) ( 3.2 ) =3.6

(c) Runge-Kutta order four


Step 1 :

h
K 1=f ( xi , y i ) , y m 1 = y i+ K 1
2

Step 2 :

h
h
K 2=f x i + , y m 1 , y m 2= y i + K 2
2
2

Step 3 :

h
K 3=f x i + , y m 2 , y m 3= y i +h K 3
2

Step 4:

1
K 4 =f ( x i+1 , y m 3 ) , y i +1= y i +h (K 1+2 K 2 +2 K 3+ K 4 )
6

(
(

Calculation :

)
)

K 1=f ( t 0 , y 0 )=1+

( 12 )=3

h
0.5
y m 1= y 0 + K 1 =2+
3=2.75
2
2

( )

h
2.7 5
K 2=f t 0 + , y m 1 =1+
=3.2
2
1.2 5

) ( )

h
0.5
y m 2= y 0 + K 2 =2+
3.2=2. 8
2
2

( )

h
2.8
K 3=f t 0 + , y m 2 =1+
=3.2 4
2
1.25

) ( )

y m 3= y 0 +h K 3 =2+ ( 0.5 ) 3.24=3.62


K 4 =f ( t 1 , y m 3 ) =1+

=3. 4133
( 3.62
1.5 )

1
1
y 0.5= y 0+ h ( K 1+ 2 K 2 +2 K 3 + K 4 ) =2+ ( 0.5 )
( 3+ ( 2 ) 3.2+ ( 2 ) 3.24+3.4133 ) =3.6078
6
6

()

(d) Predictor-corrector method


p
Step 1: K 1=f ( xi , y i ) , y i +1= y i +h K 1

Step 2:

h
p
K 2=f ( x i+1 , y i=1
) , y ci+1= yi + 2 ( K 1+ K 2 )

Calculation :
K 1=f ( t 0 , y 0 )=1+

( 12 )=3

p
y 0.5
= y 0 + h K 1 =2+ ( 0.5 ) 3=3.5

=3. 33
( 3.5
1.5 )

p
K 2=f ( x 0.1 , y 0.1
)=1+

h
0.5
y c0.5= y 0 + ( K 1+ K 2 )=2+
( 3+3. 33 ) =3.5833
2
2

(e) Extrapolation method, M=4*


Step 1 :

h
h
K 1=f ( xi , y i ) , x m=x i + , y m 1= y i +
K
4
4 1

Step 2 :

h
h
K 2=f ( xm 1 , y m 1 ) , x m 2=x i + , y m 2= y i +
K
2
2 2

Step 3 :

K 3=f ( x m 2 , y m 2 ) , x m 3 =xi +

Step 4 :

K 4 =f ( x m 3 , y m 3 ) , x m 4 =xi + h , y m 4= y m 2 +

()

()

3h
h
, y m3= y m 1+
K
4
2 3

()

( h2 ) K

Step 5:

K 5=f ( x m 4 , y m4 ) , y i+1=

Calculation:
2
K 1=1+ =3
1

()

x m 1=1+

( y m 3 + y m 4)
h
2+
K
8 5

()

0.5
=1.125
4

0.5
=1.25
2

K 2=1+

75
=3.1111
( 2.3
1.1 25 )

K 3=1+

=3. 2222
( 2.7778
1.25 )

x m 3=1+

K 4 =1+

=3.3131
( 3.1805
1.3 75 )

x m 4=1+ 0.5=1. 5

K 5=1+

=3. 4041
( 3.6061
1.5 )

x m 2=1+

1.5
=1.375
4

y m 1=2+

( 0.54 )3=2.3 75

y m 2=2+

( 0.52 ) 3.1111=2. 7778


( 0.52 ) 3.2222=3.1805

y m 3=2.3 75+

( 0.52 )3.3131=3.6061

y m 4 =2.7778+

y 0.5=

(3.1805+ 3.6061)
=3.6061
0.5
2+
3.4041
8

( )

3. Results and discussions


(a) Euler method

Euler Method
9
8
7

y (t)

h=0.05

h=0.1
h=0.2

h=1

Exact

2
1
0
1

1.2

1.4

1.6

1.8

2.2

1. The line plotted with respect to h=1 is the least accurate as it is the farthest from
the line plotted with the exact solution.
2. The line plotted respect to h=0.05 is the nearest to the exact solution which
means that it is the most accurate answer compare with others.
3. The smaller the value of the step size, h the more accurate it is to the exact
solution.

(b) Midpoint Method

Midpoint Method
10
9
8
7

h=0.05

6
y (t)

h=0.1

h=0.2

h=1
Exact

3
2
1
0
1

1.2

1.4

1.6

1.8

2.2

1. By using the midpoint method, the step size of 1 will also give us the least
accurate answer compare to the others.
2. As for the h=0.1 and h=0.05, there are more accurate as their line is more
near to the exact solution line.
3. For the midpoint method, the smaller the value of h, the closer the line to
the exact solution and means it is more accurate.

(c) Runge-Kutta Order Four

Runge-Kutta Order Four


10
9
8
7
h=0.05

6
y (t)

h=0.1

h=0.2
h=1

Exact

3
2
1
0
1

1.2

1.4

1.6

1.8

2.2

1. The step size value of h=0.1 is still the most inaccurate line as it is very
far away from the exact solution line.
2. The step size value of h=0.05 is the most accurate line as it is the nearest
to the exact solution line.
3. Overall, the line plotted with the smaller value of h will give us the most
accurate answer compare to the others.

(d) Predictor-corrector Method

Predictor-corrector Method
10
9
8
7

h=0.05

6
y (t)

h=0.1

h=0.2

h=1
Exact

3
2
1
0
1

1.2

1.4

1.6

1.8

2.2

1. The biggest step size value used, h=1 will give us the most inaccurate
answer.
2. The smallest step size value of h=0.05 line is the closest to the exact
solution line which means it is the most accurate answer.
3. The smaller the step size value, the more accurate it is to the exact
solution.

(e) Extrapolation Method

Extrapolation Method
10
9
8
7

h=0.05

6
y (t)

h=0.1

h=0.2

h=1
Exact

3
2
1
0
1

1.2

1.4

1.6

1.8

2.2

1. The h=1 line is still the most inaccurate answer as it is very far away from
the exact solution line.
2. The h=0.05 line is the most accurate answer as it is the nearest to the
exact solution line.
3. As the all the method above, the smaller the step size value, the more
accurate it is to the exact solution.

(f) Comparison of results from (a) to (e) using h=1

Graph of different method using h=1


10

Euler

Midpoint
y (t)

Runge Kutta

Predictor-corrector
Extrapolation

Exact

4
1

1.2

1.4

1.6

1.8

2.2

1. From the graph above, we can see that the Euler method is the least
accurate as it is very far from the exact solution line.
2. Extrapolation method is the most accurate method as it is the nearest to
the exact solution line.
3. The orders for all the method staring from the most accurate is
extrapolation method, Runge-Kutta order four method, Midpoint method,
predictor-corrector method and Euler method.

(g) Predictor-prey problem

h=0.1, L(0)=450, S(0)=1000


1500
Lion

1000

Sheep

500
0
0

10

20

30

40

50

60

h=0.1, L(0)=500 , S(0)=1000


1200
1000

Lion

800

Sheep

600
400
200
0
0

10

20

30

40

50

60

h=0.1, L(0)=550 , S(0)=1000


1500
Lion

1000

Sheep

500
0
0

10

20

30

40

50

60

1. The first and the third graph is like a sinusoidal wave where the number sheep
will also increase or decrease before lion.
2. The second graph is a straight line graph where the number of lion and sheep
always remain constant.
3. The initial condition will affect the pattern of the graph.

Conclusion
The extrapolation is the most accurate method among those five methods. However, it
requires the most input of formula to get the answer. On the other hands, Euler method
requires the least input of formula. In general, extrapolation method is the most accurate
method followed by Runge-Kutta method, midpoint method, predictor-corrector method
and lastly Euler method.

Вам также может понравиться