Professional Documents
Culture Documents
TECHNOLOGY
TABLE OF CONTENTS
Abstract 3
CHAPTER 1: INTRODUCTION 4
Software: MATLAB 4
Numerical methods for Ordinary Differential Equations(ODE) 5
1
CHAPTER 3: RESULTS AND PRESENTATION 4
Calculation: Formula 7
Calculation: Implicit Euler method 8
Exact Solution 9
Explicit Euler Method 10
Implicit Euler Method 11
3rd order Taylor method 13
Midpoint method (RK2) 15
Runge Kutta method (RK4) 17
Predictor - Corrector method 18
Error Analysis 20
Comparison of each method with the Exact Solution at step size, h = 0.1 20
Comparison of each method step size, h = 0.1, 0.5, 1.0, 1.5, 2.0 final value
with the exact solution 21
Comparison of each method value with the exact solution as the value t
increases 24
CHAPTER 4: DISCUSSIONS 25
Numerical Methods 25
Error Analysis 25
CHAPTER 5: CONCLUSION 28
REFERENCE 28
ABSTRACT
Abstract
In this report, each group are to select an Ordinary Differential Equation (ODE)
question from the list of twelve questions. Students are expected to solve the following
equations using numerical computational software like MATLAB and SciLab. Microsoft
Excel and any ODE functional packageis not advised to be used. The ODE are expected to be
solved through numerical methods for instances :
1. Explicit Euler method,
2
2. Implicit Euler method,
3. 2nd order Taylor method
4. 3rd order Taylor method,
5. Midpoint method, RK2
6. Runge Kutta method, RK4
7. Predictor - Corrector method
8. two-steps Adam-Bashforth method
9. four-steps Adam-Bashforth method
10. two-steps Adam-Moulten method
11. four-steps Adam-Moulten method
12.Extrapolation method
After solving the particular ODE problems, comparison between each numerical
method is done and observed. The error and error percentage for each method is determined
from the difference between the final value of each methods and the exact solution. Different
step sizes, h for each method are also used and its effect on the accuracy of the solution is
determined. The parameters of ODE affecting the accuracy of the results are then discussed
and a conclusion is drawn.
3
CHAPTER 1
INTRODUCTION
Software: MATLAB
Algorithm development
4
Numerical methods for Ordinary Differential Equations (ODE)
Ordinary differential equation (ODE) is one of the two types of differential equation
which contains one or more functions of one independent variable and its derivatives. The
other differential equation is the partial differential equation which is contrast to ODE and
has more than one independent variable.
Numerical methods for solving first-order initial value problems (IVPs) can be solved
by all kinds of categories: linear multistep methods, or Runge-Kutta methods are famous for
their accuracy to the exact value in spite of the difficulty to carry them out. On the other
hand, a further division can be done by dividing methods into those that are explicit and those
that are implicit (Adams-Moulton methods). Explicit examples from the linear multistep
family include the Adams-Bashforth methods, any Runge-Kutta method and any Taylor
method. In default, any stiff differential equations will require the use of implicit schemes,
whereas non-stiff problems can be solved more efficiently with explicit schemes.
5
6
CHAPTER 2
OBJECTIVE AND PROBLEM STATEMENT
Objective
1 To solve the ordinary differential equations question using any suitable analytical
software. Software: MATLAB
1. To analysis and discuss the comparison in the results that generates by the software
and by Microsoft Excel.
2. To study the error percentage between both of this software and determine the best
method for the ordinary differential equation question.
Problem Statement
From a long time ago, engineers and scientists has emphasized on high efficiency
processing. Deprived from the versatility of computational accuracy, numerical
approximation method calculated through handwritten are laden with human errors at the
time, hence does not yield high efficiency yet consume a big amount of time. However, with
the new wind of technology, new software are developed to overcome these issue and bring
productivity by minimizing the error created, which in return, increase each problem solving
efficiency.
7
We are assigned to solve the problem below by using 5 methods: Euler method,
Taylor method, Runge Kutta method, Midpoint method and Predictor - Corrector method.
Besides using MATLAB, Microsoft excel is used to solve the following ODE problem too.
The purpose of using Microsoft excel is to compare the result generated by MATLAB. With
the exact equation given, the exact value of each particular point is taken to determine the
error and effect of each methods and each methods variation. We are using step size h=0.1,
0.5, 1.0, 1.5, and 2.0 for all the methods.
Calculation: Formula
x i+1=x i +hf ( t i , x i)
h h
k 1=f ( t i , x i ) , x m=x i + k 1 t m=t i+
2 2
b) Implicit Euler Method,
Taylor method,
h2 ' (t , x ) h3 '' (t , x )
x i+1=x i +hf ( t i , x i) + f i i
+ f i i
2! 3!
8
e) Runge Kutta method (RK4) f) Predictor - Corrector method
k 1=f ( t i , x i ) , x i+1 p= xi +h k 2
Calculation
Implicit Euler method:
dx 4x
f ( t i , x i )= dt 7t t
2
4 x i +1
f ( t i+1 , xi +1 )=7 t 2i+1
t i +1
4 xi +1
x i+1=x i +h(7 t 2i+1 )
t i +1
4 h x i+1
x i+1=x i +7 h t 2i +1
t i+1
4h
x i+1 (1+ )=xi +7 h t 2i+1
t i+1
xi +7 h t 2i+1
x i+1=
4h
(1+ )
t i+1
9
xi t i+1 +7 h t 3i +1
x i+1=
t i +1+ 4 h
MATLAB Code
a) Exact Solution
1
x(t ) t 3
t4
10
Graph 1: Exact Solution MATLAB Graph
11
Graph 2(a): Euler Explicit Method with step size, h = 0.1 MATLAB Graph
12
x = zeros(1,length(t)); %Plot result
x(1) = 2; hold on
ylabel('x');
hold off
x(i+1) =
(t(i+1)*x(i)+7*h*t(i+1)^3)/(t(i+1)+4*h);
end
MATLAB Graph
Graph 3(a): Euler Implicit Method with step size, h = 0.1 MATLAB Graph
13
Graph 3(b) : step size, h = 0.5 Graph 3(c) : step size,
h = 1.0
14
set(gca,'Fontsize',16) hold off
MATLAB Graph
Graph 4(a): 3rd order Taylor Method with step size, h = 0.1 MATLAB Graph
15
Graph 4(d) : step size, h = 1.5 Graph 4(e) :
step size, h = 2.0
16
grid xlabel('x')
title('Midpooint Method, h = 0.1, 0.5, 1.0, set(gca,'Fontsize',16)
1.5 and 2')
hold off
tlabel('t')
MATLAB Graph
Graph 5(a): Midpoint Method (RK2) with step size, h = 0.1 MATLAB
Graph
17
Graph 5(d) : step size, h = 1.5 Graph 5(e) :
step size, h = 2.0
%parameters % update t
h=0.1; %step size, change to h = 0.5, 1.0, % update x
1.5 and 2
k1=f(t(i),x(i));
t = 1:h:6; %solve from t=[1,tfinal]
k2=f(t(i)+0.5*h,x(i)+0.5*k1*h);
%initial condition
k3=f(t(i)+0.5*h,x(i)+0.5*k2*h);
x = zeros(1,length(t));
k4=f(t(i)+h,x(i)+k3*h);
x(1)=2;
x(i+1)=x(i)+h/6*(k1+2*k2+2*k3+k4);
%Define ODE function handle
end
f=@(t,x) (7*(t^2)-(4*x)/t);
%Plot result
%RK4 Loop
hold on
for i=1:(length(x)-1)
plot(t,x)
18
grid xlabel('x')
title('Runge Kutta RK4, h = h = 0.1, 0.5, set(gca,'Fontsize',16)
1.0, 1.5 and 2')
hold off
tlabel('t')
MATLAB Graph
Graph 6(a): Runge-Kutta Method (RK4) with step size, h = 0.1 MATLAB Graph
19
Graph 6(d) : step size, h = 1.5 Graph 6(e) :
step size, h = 2.0
20
MATLAB Graph
Graph 7(a): Predictor - Corrector method with step size, h = 0.1 MATLAB
Graph
Error Analysis
a) Comparison of each method with the Exact Solution at step size, h = 0.1
Exact Solution Final Value, x(6) = 216.0007716
Calculation:
1. Error = |exact solution, x(6) numerical method, x(6)|
|
2. Error Percentage ( ) =
exact solution , x ( 6 ) |
exact solution, x ( 6 ) numerical method , x ( 6 )
100
200
Exact Solution x(t)
Explicit Euler x(i)
150 Implicit Euler x(i)
Taylor 3rd Order x(i)
x (i)
100 Midpoint x(i)
Runge Kutta 4th Order x(i)
Predictor Corrector x(i)
50
0
1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6
t(i)
t(i)
b) Comparison of each method step size, h = 0.1, 0.5, 1.0, 1.5, 2.0 final value with the
exact solution
Error is obtained by comparing each step size final values with respect to exact solution
values :
1. For step size, h= 0.1, 0.5, 1, x(6) of each numerical method is compared with exact
solution values, x(6) values
2.For step size, h=1.5, x(5.5) of each numerical method is compared with exact solution
values, x(5.5) values
3. For step size, h= 2, x(5) of each numerical method is compared with exact solution values,
x(5) values
i) Explicit Euler Method:
50
Explicit Euler x(i)
40 Implicit Euler x(i)
Taylor 3rd Order x(i)
Error Percentage (%) 30
Midpoint x(i)
20 Runge Kutta 4th Order x(i)
Predictor Corrector x(i)
10
0
0 0.2 0.40.60.8 1 1.21.41.6 1.8 2
Step Size, h
c) Comparison of each method value with the exact solution as the value t increases
E.g.: Explicit and Implicit Euler method at step size, h = 0.1
Explicit Implicit Explicit Implicit
Exact
Euler Euler Euler Euler
Percenta Percenta
i h t x(i) x(i) x(i) ge Error ge Error
(%) (%)
1 0.1 1.00 2.0000 2.0000 2.0000 0.00 0.00
10 0.1 1.90 6.7199 7.1451 6.9357 3.11 3.02
20 0.1 2.90 23.9721 24.8299 24.4031 1.77 1.75
30 0.1 3.90 58.5564 60.0833 59.3233 1.29 1.28
40 0.1 4.90 116.4443 118.8479 117.6507 1.03 1.02
50 0.1 5.90 203.6329 207.1152 205.3798 0.85 0.84
4
Explicit Euler
Erro Percentage (%) 3
Implicit Euler
2
0
1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6
t(i)
Chapter 4: DISCUSSIONS
A) Numerical Methods
All numerical methods graph yield similar pattern as the exact solution function yet
with different result. The results however do not have much different with each numerical
method respectively which all fall in about the same region of x value ranged from 200 to
250 when t value is 6. One obvious notice in the change of graph is when the step size of the
ODE numerical methods changes. 1. We used the step size value of 0.1. The purpose of using
such small step size is to obtain a more accurate result. However when the step size is small,
more step is required to calculate the problem from the initial condition to the final desired
value. For our case, we are given X(1)=1 and we are required to find the value when X(6).
With a smaller step size, thus it will have more data, with more data, the graph generated will
be smoother and closer to the actual graph. But as the step sizes increase, the smoothness of
curve in each method reduced, giving it a rocky shape. The nodes of the graphs also
decreased as the step sizes increases. This causes the number of conjoining linear function
in the graph to decrease. The length of the MATLAB also varied from methods to methods.
In spite of that, Runge Kutta method, RK4 is observed to have the most code while the Euler
methods have the least code. This shows that the better and more efficient numerical methods
like RK4 are much more tedious to be perform compare to a simpleton Euler Method that
yield less accurate result.
B) Error Analysis
From the table above, the percentage error for Implicit Euler method compared with
exact solution is always smaller than Explicit Euler method. The errors for both method
however decreases when t increases. This resulting pattern is also observed in the rest of the
numerical methods. The step size taken is relatively small, the x(i) values taken at t=6 for
Euler methods are close to exact number. Comparing both Euler methods, implicit method is
proven to give better result than the explicit method. However, their result is only second to
RK methods like Midpoint method and Runge Kutta method.
3rd order Taylor method, > Explicit Euler method, > Predictor - Corrector method > Midpoint
method, RK2 > Implicit Euler method > Runge Kutta method, RK4
To retain performance, any numerical methods with error percentage over 10% have to be
rejected, causing step sizes, h = 1.5 and 2 inappropriate to use in this ODE system. In
contrast, we can accept all step sizes for Runge-Kutta method as all its error percentage are
lower than 10%. On the other hand 3rd order Taylor method is proved to be by far the worst
method, with only step sizes, h=0.1 and 0.5 values can be accepted. Thus in the process of
solving the ODE problem, we had discovered the advantages and disadvantages for each of
the method. In term of the software platform used, we can said:
Source code is available online for free. It can be modified and upgraded at no cost.
Statements or code in MATLAB can wrote and calculated immediately. They can be
tested as with just a push of a button.
Relatively easy and user friendly to use compare to others software code such as C
programming, Python and Java.
It is able to manage large groups of mathematical workings with just a few lines of
command. Further mathematical workings may not be needed as it can calculate the
mathematical problem itself
Easy to enter, locate and format data as there are columns and rows provided and
labelled with numbers and alphabets
Can use it easily without any professional training.
Can work quickly in analysing large amounts of data and produce graphs from it
Pivots tables can be used to group or separate the data.
The mathematical workings written inside Microsoft Excel are longer if the step size
used becomes smaller.
More difficult to troubleshoot and locate human error.
Chapter 5: CONCLUSION
From this assignment, we managed to solve an 2nd order ODE problem with a
numerical computational software. It is discovered that MATLAB is a more accurate software
that can solve ODE easily and instantly. Although it required us to learn its programming
algorithm before proceeding to the actual problem solving, it also require less lines of
command to be written compare to Microsoft Excel. This ultimately save us more time and
energy to solve the ODE problem but with the condition of mastering the programming skill
of MATLAB. On the other hand, Microsoft Excel required more lines of command but it is
relatively easier to learn. Nonetheless, both of the software was equally accurate in
calculating the problem given in this assignment. We found that in increasing order of
efficiency:
3rd order Taylor method, > Explicit Euler method, > Implicit Euler method, >
Predictor - Corrector method > Midpoint method, RK2 > Runge Kutta method, RK4
Runge-Kutta method, RK4 is the best numerical method to solve this ODE problem as it has
0% error for step size, h = 0.1 and below 10% for all step-sizes used. Taylor 3rd order method
is proven by far the worst method to solve this ODE problem as it has 1.67% error for step
size, h = 0.1 and above 10% once it step sizes is equal or more to 1.0. We also study the effect
of step-sizes and numerical parameter t to the accuracy of the numerical method. As the t
value increase, the error obtained from each method decreases while as the step-sizes increase
the error percentage obtained from each method increases, Thus to obtain best solution to this
2nd order ODE problem, we are advised to use Runge-Kutta method with smaller step-size,
and with respect to more t value numerical parameter.
REFERENCES
1. Bradie, Brian (2006). A Friendly Introduction to Numerical Analysis. Upper Saddle River,
New Jersey: Pearson Prentice Hall. ISBN 0-13-013054-0.
2. Halliday, David; Resnick, Robert (1977), Physics (3rd ed.), New York: Wiley, ISBN 0-471-
71716-9 3.
3. MATLAB- The Language of Technical Computing, online(available):
https://www.mathworks.com/products/matlab.html
4. http://www.math.unipd.it/~alvise/CS_2008/ODE/MFILES/ode.pdf
5. http://www.math.ubc.ca/~feldman/math/vble.pdf