Lecture 9, Numerical Method ODE
Lecture 9, Numerical Method ODE
Engineering Applications
(GENG-8030)
By:
Dr. Hassanzadeh
Lecture number 9:
ODE, and Numerical ODE in MATLAB
Winter 2023
ODE in MATLAB
• MATLAB has several built-key functions to solve some special cases of
ODEs, such as
• ode45, ode23, ode15s, ode113, …..
• Each of these uses certain well-known numerical methods.
Solving first order differential equations:
ode45 (used in this course) is used as follows to solve
The code is
f=@(t,y)(dy/dt)
Actual solution is :
1.5
Voltage(v)
1
0.5
0
0 0.1 0.2 0.3 0.4 0.5
Time(s)
Computational methods and modeling for engineering applications (GENG-8030) 4
Example : We solved the following by integration factor or variation of parameters in ENG-Math
dh 0.0344 h
dt 10h h 2
Draining of a
spherical tank
5
y 7 y 4 y sin(t )
Define and . Then the above equation can be expressed as two equations:
5 +7 +4 =sin(t)
This form is sometimes called the Cauchy form or the state-variable form.
my cy ky f (t )
at is around:
a) (correct)
a) (correct)
5.5
4.5
3.5
2.5
1.5
0 1 2 3 4 5 6
• ODE45 and the finite difference method are two different approaches to solving differential
equations.
• ODE45 is a numerical method for solving ordinary differential equations (ODEs) that uses a variable
step size to balance accuracy and computational efficiency. It is a built-in function in MATLAB that
uses an adaptive Runge-Kutta method to solve the ODEs. ODE45 is a powerful tool for solving ODEs
with a high level of accuracy and is often used in scientific computing, engineering, and other fields.
• On the other hand, the finite difference method is a numerical method for approximating solutions
to differential equations by discretizing the domain of the problem into a grid and approximating
the derivatives using finite differences. It is a general method that can be applied to both ODEs and
partial differential equations (PDEs). The finite difference method is relatively easy to implement
and can be used to solve problems with complex boundary conditions or geometries.
• In terms of computational efficiency, the finite difference method is generally faster than ODE45 for
simple ODEs with regular geometries, especially if the problem size is large. However, ODE45 is
generally more accurate and reliable for solving ODEs with complex geometries or boundary
conditions.
• Overall, the choice between ODE45 and the finite difference method depends on the specific
problem being solved and the trade-off between accuracy and computational efficiency.
Comparing two methods
• In general, it is difficult to say which method is more accurate between ODE45 and the finite
difference method without considering the specific problem being solved.
• ODE45 is a high-order method that uses an adaptive step size to control the error of the solution,
which makes it very accurate for solving ODEs. However, it is not always the best choice for problems
with irregular geometries or non-smooth solutions.
• The finite difference method, on the other hand, is a lower-order method that uses a discretization of
the domain and approximation of the derivatives to compute the solution. The accuracy of the finite
difference method depends on the grid size, the order of the approximation, and the smoothness of
the solution.
• In general, the finite difference method can be very accurate for problems with regular geometries
and smooth solutions, especially when higher-order methods are used. However, it may be less
accurate than ODE45 for problems with complex geometries or non-smooth solutions.
• Therefore, it is important to carefully consider the problem being solved and the properties of the
solution before choosing a method. In practice, it may be necessary to try both methods and
compare the results to determine which one is more accurate for a given problem.