0% found this document useful (0 votes)
25 views28 pages

Lecture 9, Numerical Method ODE

The document discusses the use of MATLAB's built-in functions, particularly ode45, for solving ordinary differential equations (ODEs) in engineering applications. It covers various examples, including first-order and higher-order ODEs, and compares the effectiveness of the ode45 method with the finite difference method. The choice of method depends on the specific problem, balancing accuracy and computational efficiency.

Uploaded by

vileji2030
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views28 pages

Lecture 9, Numerical Method ODE

The document discusses the use of MATLAB's built-in functions, particularly ode45, for solving ordinary differential equations (ODEs) in engineering applications. It covers various examples, including first-order and higher-order ODEs, and compares the effectiveness of the ode45 method with the finite difference method. The choice of method depends on the specific problem, balancing accuracy and computational efficiency.

Uploaded by

vileji2030
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

Computational Methods and Modeling for

Engineering Applications
(GENG-8030)

Department of Electrical and Computer Engineering,


University of Windsor, ON, Canada,

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

on t-interval [a, b] for initial value y0

The code is

f=@(t,y)(dy/dt)

Ode45(f, [a, b], y0)

• We need an initial value y0 (the function y at t=0).

• ode45 is based on a numerical method called Runge-Kutta (4,5)

• Therefore, we can use ode45 to solve ODE of first order that we


learned to solve using integration factor, variation of parameters
and exact equations. The initial value y(0) implies that in theory
we can use Laplace transformation to solve these ODEs.
Response of an RC circuit

The circuit model for zero input voltage v is (y is output voltage)

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

• Solve y’+5y=3 with y(0)=3.


Example: In Eng-Math we used method of exact equation for the following

• Solve 2xy^2dx+2(x^2y-1) dy=0 with y(0)=1 on interval [-2,2]


Nonlinear example:
The equation for the height is

dh 0.0344 h

dt 10h  h 2

Draining of a
spherical tank

Computational methods and modeling for engineering applications (GENG-8030) 7


Higher Order ODE using ode45
• The step sizes for t in ode45 varies. The are NOT equal step sizes.
• This is done by ode45 to get more accurate answers.

• Next step we use ode45 to solve higher order ODEs.


• f=@(t,y)[ y(2); y(2)’]
• Ode45(f, [a, b], [y0; y0])
Example: on t-interval [0,4] solve

• We turn this order 1:


Look at the plotting: in fact y is a
vector containing both y(1) and y(2)
,
• Plots
Extension to higher order equations:
To use the ODE solvers to solve an equation higher than order 2, you must
first write the equation as a set of first-order equations.
For example, consider the equation

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.

Computational methods and modeling for engineering applications (GENG-8030) 11


Extension to higher order equations:

=-7/54/5 1/5 sin(t)

with 0 t 6 with the initial conditions


(0)=3 and (0)=9.

Computational methods and modeling for engineering applications (GENG-8030) 12


Pendulum example:

The pendulum shown consists of a


concentrated mass m attached to a rod
whose mass is small compared to m. The
rod’s length is L. The equation of motion for
this pendulum is

Suppose that and . Use MATLAB to solve


this equation for i rad.

Computational methods and modeling for engineering applications (GENG-8030) 13


Pendulum example:

Computational methods and modeling for engineering applications (GENG-8030) 14


A mass and spring:
A mass and spring with viscous surface friction. Its equation of motion is

my cy  ky  f (t )

Computational methods and modeling for engineering applications (GENG-8030) 15


A mass and spring:
The equation of motion can be put into the state variable form. Assuming
and y’ we have

Computational methods and modeling for engineering applications (GENG-8030) 16


A mass and spring: Solve it for f=10, m=1, c=2, k=5 for
and

Computational methods and modeling for engineering applications (GENG-8030) 17


Question:
Q6- Use MATLAB to compute and plot the solution of the following
equation.

at is around:

a) (correct)

Computational methods and modeling for engineering applications (GENG-8030) 18


Question:
Q7- Plot the position and velocity of a mass with a spring and damping,
having the parameter values , , and . The applied force is , the initial position
is , and the initial velocity is . H
The displacement at is

a) (correct)

5.5

4.5

3.5

2.5

1.5
0 1 2 3 4 5 6

Computational methods and modeling for engineering applications (GENG-8030) 19


General case: Using ode45 to solve
Idea of Finite Difference (FD) method
Here we have two boundary conditions at points t1 ad t1 and we divide the interval
[t1,t2] to whatever equal step sizes that we like. We can solve the ODE to find the
value of functions at all those points(that we determined) between t1 and t1.
FD method
Example: Temperature distribution in a pin fin in terms of second order ODE
Solution for the example
solution
Comparison between ODE45 and finite difference method

• 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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy