0% found this document useful (0 votes)
5 views20 pages

Computing Solutions of Ordinary Differential Equations

The document discusses numerical methods for solving ordinary differential equations (ODEs), focusing on techniques such as Euler's method, Modified Euler’s method, and the Runge-Kutta fourth-order method. It highlights the importance of these methods in engineering problem analysis and provides MATLAB code examples for implementation. The document also mentions the ability to solve multiple ODEs simultaneously using vectors in MATLAB.
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)
5 views20 pages

Computing Solutions of Ordinary Differential Equations

The document discusses numerical methods for solving ordinary differential equations (ODEs), focusing on techniques such as Euler's method, Modified Euler’s method, and the Runge-Kutta fourth-order method. It highlights the importance of these methods in engineering problem analysis and provides MATLAB code examples for implementation. The document also mentions the ability to solve multiple ODEs simultaneously using vectors in MATLAB.
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/ 20

Computing solutions of

Ordinary differential equations


Introduction

● Numerical methods for ordinary differential equations (ODEs) are methods


used to find numerical approximations to the solutions of ODEs.
● Their use is also known as numerical integration.
● Many differential equations are generated because of engineering problem
analysis, most of which cannot be easily solved.
● These equations can be solved numerically using a computer.
● We can use microsoft Excel to do this but in this text we will use MATLAB
● The problems that contain first-order ODEs are solved by employing methods
of Euler, modified Euler, midpoint, Heun, and Runge-Kutta second, third, and
fourth order.
Euler’s method
● The Euler method is a practical numerical method. The Euler method is a
first-order numerical procedure for solving ODEs with a given initial value.
● Divide the region of interest [a,b] into discrete values of x = nh, n = 0, 1,….N
spaced at intervals h = (b - a)/N.
● It can be shown that
Example 1 (using Euler’s method)
Solve the following differential equation using the Euler’s method for x = [0 0.5]
with initial condition y(0) = 2. The first-order differential equation is:
● In the previous slide, the function EL is a general function that implements
Euler’s method.
● This will become a blueprint for all the solutions of all problems that involve
solving first order differential equations.
● Solving our previous problem will look like
Modified Euler’s method
● The Euler forward structure required a very small step size for a reasonable
result. The Euler method might be very simple to implement, but it cannot give
precise solutions.
● This is where Modified Euler’s method comes in.
● It is given by the formula

The second yn + 1 is determined using euler’s method


● Now we can write a separate custom function or method known as ME, where
we code the implementation of the modified Euler’s method once and re-use
the function or method multiple times.
● Here is the code for this method
Example 1 (Using Modified Euler’s method)
Runge Kutta fourth order method
Runge-Kutta method is popular and uses several predictive steps instead of just
one. It involves calculating four auxiliary quantities k1, k2, k3 and k4. The fourth-
order Runge-Kutta algorithm is:
● Note that, while all the algorithms presented are for first-order equations with
one dependent variable, they can be readily extended to systems of higher-
order differential equations.
● The MATLAB function, ODE4, implements the classic Runge-Kutta method,
which is the most widely used numerical method for ODEs.
● The MATLAB function for the classical fourth-order Runge-Kutta method is
shown below
Using the same example as before, we get
A summary of all these methods in a single table will look like
When these are plotted on the same graph, we get
The methods are ordered in increasing accuracy. Thus, the Runge-kutta fourth-
order method is the ideal numerical method for solving first-order differential
equations.
Note that sometimes you will be required to calculate the percentage error for a
given method. For example, using modified euler for h = 0.2, the percentage error
is computed using the formula

The equivalent of this in MATLAB will look like


Solving two or more ODEs simultaneously using numerical methods

● The logic will remain the same only that we will mainly use vectors instead of
scalars.
● But good enough MATLAB makes working with matrices almost the same as
working with scalars. In fact, according to MATLAB, a scalar is a vector that
has exactly one element.
● If we attempt to write out our functions to mimic the ode45 solver that comes
with the software, then we are restricted to using only 3 inputs: the ode
function, the tspan, and Y0.
● The example below shows how we can pull off this using the runge kutta
fourth-order method

You might also like