You are on page 1of 11

# FACULTY OF ENGINEERING AND TECHNOLOGY

LAB REPORT
COMPUTATIONAL METHODS FOR MECHANICAL
ENGINEER
EME 3156
TRIMESTER 2 (2015/2016)
Experimen
t1
Date of
Experimen
t

## Numerical Solution of ODE

17th December 2015

Student Name
Lee Chng Keat

Student ID
1122700207

Objectives:
1. Using excel to solve ODE initial value problems.
2. Using different method to solve the problem which is Euler method, Midpoint

## method, Predictor corrector method and Runge-Kutta Method.

3. Find out the method that gives the most accurate answer.
y = 1+(y/t)+(y/t)^2 , y(1) = 0, y(3) = ?
t
c +log

y(t) =

t tan
When t = 1, y = 0
1 = 1 tan (c + log 1)
c=0
3
0+ log

y(t) =

( 3 ) tan
y = 5.8741

7
6
5
4
3
2
1
0

## Euler method equation: yi+1 = yi + hf(ti,yi)

Let h = 0.05 i=1
t1 = 1.05 y1 = 0.05 h = 0.05
f(t1,y1) = 1 + (y1/t1) + ( y1/t1)2
= 1.049887
y2 = 157587
When t=3
Error (h=0.05) = |5.8741-5.420458| = 0.453642
Error (h=0.1) = |5.8741-5.05988| = 0.81422
Error (h=0.2) = |5.8741-4.514277| = 1.359823
Error (h=0.5) = |5.8741-3.54973| = 2.32437
Error (h=1.0) = |5.8741-2.75| = 3.1241
7
6
5
4
3

Exact
h = 0.05

h = 0.1

h = 0.5

h = 0.2
h=1

## Midpoint method equation: yi+1 = yi + hK2

Let h=0.05 i=1
t1 = 1.05, y1 =0.051249, h = 0.05
K1=f(t1,y1) = 1 + (y1/t1) + ( y1/t1)2
= 1.051191
tm = ti + h/2 = 1.05 + 0.05/2 = 1.075
ym = yi + (h/2)K1 = 0.051249 + (0.05/2)* 1.051191 = 0.077529
K2 = f(tm,ym) = 1 + (ym/tm) + ( ym/tm)2
= 1.077321
Y2 = y1 + hK2
= 0.105115

When t=3
Error (h=0.05) = |5.8741-5.864075| = 0.010025
Error (h=0.1) = |5.8741-5.836088| = 0.038012
Error (h=0.2) = |5.8741-5.738647| = 0.135453
Error (h=0.5) = |5.8741-5.287636| = 0.586464
Error (h=1.0) = |5.8741-4.524779|= 1.349321

7
6
5
4

Exact

h = 0.05

h = 0.1

h = 0.2

h = 0.5
h=1

## Midpoint Graph different h value Y versus t

Fourth order Runge-Kutta method equation: yi+1 = yi +

h
6 (K1+2K2+2K3+K4)

## Let h=0.05 i=1

t1 = 1.05, y1 = 0.05127, h = 0.05
K1 = f(t1,y1) = 1 + (y1/t1) + ( y1/t1)2
= 1.051213
tm = ti + h/2 = 1.05 + 0.05/2 = 1.075
ym1 = yi + (h/2)*K1 = 0.05127 + (0.05/2)* 1.051213= 0.077551
K2 = f(tm,ym1) = 1 + (ym1/tm) + ( ym1/tm)2
= 1.077344
ym2 = yi + (h/2)*K2 = 0.05127+ (0.05/2)* 1.077344= 0.078204
K3 = f(tm,ym2) = 1 + (ym2/tm) + ( ym2/tm)2
= 1.07804
ti+1 = ti + h = 1.05 + 0.05 = 1.1
ym3 = yi + hK3 = 0.05127 + 0.05*1.07804 = 0.105172
K4 = f(ti+1,ym3) = 1 + (ym3/ti+1) + ( ym3/ti+1)2
= 1.104753

yi+1 = yi +

h
6 (K1+2K2+2K3+K4)

= 0.10516

When t=3
Error (h=0.05) = |5.8741-5.874099| = 0.000001
Error (h=0.1) = |5.8741-5.874083| = 0.000017
Error (h=0.2) = |5.8741-5.873839| = 0.000261
Error (h=0.5) = |5.8741-5.865642| = 0.008458
Error (h=1.0) = |5.8741-5.776963| = 0.097137

7
6
5
4
3

Exact
h = 0.05

h = 0.1

h = 0.2

h = 0.5
h=1

y i+1 = yi +

h
2 (K1+K2)

## Let h=0.05 i=1

t1 = 1.05, y1 = 0.51247, h = 0.05
K1 = f(t1,y1) = 1 + (y1/t1) + ( y1/t1)2
= 1.051189
ti+1 = ti+1 + h = 1.05 + 0.05 = 1.1
P

P

= 1.103275
C

## y i+1 = yi + h/2*(K1 + K2)

= 0.105109

When t=3
Error ( h=0.05) = |5.8741-5.861999| = 0.012101
Error (h=0.1) = |5.8741-5.827854| = 0.046246

## Error (h=0.2) = |5.8741-5.70757| = 0.16653

Error (h=0.5) = |5.8741-5.149066| = 0.725034
Error (h=1.0) = |5.8741-4.238567| = 1.635533
7
6
5
4
3
2
1
0

Exact
h = 0.05
h = 0.1
h = 0.2
h = 0.5
h=1

## Comparison of Graph with different method

When h=0.05, t=3:
Error (Euler) = |5.8741-5.420458| = 0.453642
Error (Midpoint) = |5.8741-5.864075| = 0.010025
Error (RK4) = |5.8741-5.874099| = 0.000001
Error (Predictor-Corrector) = |5.8741-5.861999| = 0.012101

7
6
5
4
3

Exact

Euler Method
Midpoint Method

Runge-Kutta Method

Exercise
Given:
dL
dt

dS
dt

## Li+1 = Li + h(0.0001 Li Si 0.1 Li)

Si+1 = Si + h(0.5 Si 0.001 Li Si)
h = 0.5

Number of
Species

3500
3000
2500
2000
1500
1000
500
0
0

Lion
Sheep

50

100

150

200

Time

h = 0.2

2000
1500
Lion

Number of 1000
Species
500
0
0

Sheep

50

Time

h = 0.05

## Graph of number of species against time

1400
1200
1000
Number of Species

800

Lion

600

Sheep

400
200
0
0

50

100

150

200

Time

Discussions:
From the result shown in the table and graphs, we know that the smaller the value of step size
the lesser the percentage of error. The value in this case also will make the value to be much
more accurate by comparing to the exact value. All of the result we have calculated, h=0.05
will give the result which have the less error so we use h=0.05 for all method to compare with
method gives the lesser percentage of error and we find out it is Runge-Kutta Method (RK4).
For the exercise we have done for predator prey problem, we can see that the lions and sheep
growth in relation of time. The growth and death of this two species is vice versa to each
other. The lower step size value give a more accurate value because the number of species
against time did not deflect largely and maintain in a smooth curve.
Conclusions:
In a nut shell, we found that Runge-Kutta (RK4) method will give the best answer
which is accurate to the exact value which can be seen in the graph. This is because the other
method uses simpler calculation and lesser effort to gain the answer so the value we achieve
is less accurate to the exact method. In this lab, we have learn how to use excel to do the
calculation because in this kind of problem which required a lots of repeated steps in
calculation will cause a lot of human error without the aids of excel. We uses excel to get
lesser error as possible.