Numerical Methods
ODE
Thai Minh Quan - Numerical Methods 1
Contents
1. Introduction
2. Roots of Non-linear equations
3. Systems of linear equations
4. LU decomposition
5. Linear Programming
6. Numerical Differentiation and Integration
7. ODE
Thai Minh Quan - Numerical Methods 2
ODE
Overview
Thai Minh Quan - Numerical Methods 3
Thai Minh Quan - Numerical Methods 4
ODE
Overview
• The fundamental laws of physics, mechanics, electricity, and
thermodynamics are usually based on empirical observations
that explain variations in physical properties and states of systems.
Rather than describing the state of physical systems directly, the
laws are usually couched in terms of spatial and temporal
changes.
• Such equations, which are composed of an unknown function
and its derivatives, are called differential equations
Thai Minh Quan - Numerical Methods 5
ODE
Overview
ODE
• g is the gravitational constant, m is the mass, and c is a drag
coefficient
• v: the dependent variable.
• t: the independent variable
Thai Minh Quan - Numerical Methods 6
ODE
Overview
• When the function involves one independent variable, the
equation is called an ordinary differential equation (or ODE)
• This is in contrast to a partial differential equation (or PDE) that
involves two or more independent variables
ODE PDE
Thai Minh Quan - Numerical Methods 7
ODE
Overview
• Differential equations are also classified as to their order
Eq. above is called a first-order
A second order equation would
equation because the highest
include a second derivative
derivative is a first derivative
Thai Minh Quan - Numerical Methods 8
ODE
Overview
Thai Minh Quan - Numerical Methods 9
Euler’s method
Overview
• This part is devoted to solving ordinary differential equations of the form
the method was of the general form
where the slope f is called an increment function
Thai Minh Quan - Numerical Methods 10
Euler’s method
Euler’s method
• The first derivative provides a
direct estimate of the slope at ti
where f(ti,yi) is the differential
equation evaluated at ti and yi . This
estimate can be substituted into
Thai Minh Quan - Numerical Methods 11
Euler’s method
Example
Hint: Euler’s method
Thai Minh Quan - Numerical Methods 12
Euler’s method
Example
Thai Minh Quan - Numerical Methods 13
Euler’s method
Example
The true solution at t = 2 .0 is 14.84392 and, therefore, the true
percent relative error is 23.19%. The computation is repeated
Thai Minh Quan - Numerical Methods 14
Euler’s method
Example
this error can be
reduced by using a
smaller step size.
Thai Minh Quan - Numerical Methods 15
Euler’s method
Thai Minh Quan - Numerical Methods 16
Euler’s method
Error Analysis for Euler’s Method
1. Truncation, or discretization, errors caused by the nature of the
techniques employed to approximate values of y.
2. Round off errors caused by the limited numbers of significant
digits that can be retained by a computer.
The sum of the two is the total error. It is referred to as the
global truncation error.
Thai Minh Quan - Numerical Methods 17
Euler’s method
Stability of Euler’s Method
• The truncation error of Euler’s method depends on the step size in
a predictable way based on the Taylor series.
• A numerical solution is said to be unstable if errors grow
exponentially for a problem for which there is a bounded solution.
• The stability of a particular application can depend on three
factors:
the differential equation,
the numerical method,
the step size
Thai Minh Quan - Numerical Methods 18
Euler’s method
Stability of Euler’s Method
• Insight into the step size required for stability can be examined by
studying a very simple ODE
If y (0 ) = y0, calculus can be used to determine the solution as
Thus, the solution starts at y0 and asymptotically approaches zero
Thai Minh Quan - Numerical Methods 19
Euler’s method
Stability of Euler’s Method
• Now suppose that we use Euler’s method to solve the same
problem numerically:
We have
The parenthetical quantity (1 − ah) is called an amplification factor. If
its absolute value is greater than unity, the solution will grow in an
unbounded fashion
Thai Minh Quan - Numerical Methods 20
Euler’s method
Stability of Euler’s Method
• So clearly, the stability depends on the step size h, That is, |1 − ah|
must be less than 1
h<2/a
Euler’s method is said to be conditionally stable: h<2/a.
Thai Minh Quan - Numerical Methods 21
Euler’s method
Explicit and Implicit
• Explicit
Thai Minh Quan - Numerical Methods 22
Euler’s method
Explicit and Implicit
• Explicit
• Implicit: An implicit form of Euler’s method can be developed by
evaluating the derivative at the future time
Thai Minh Quan - Numerical Methods 23
Euler’s method
Explicit and Implicit
• Implicit: An implicit form of Euler’s method can be developed by
evaluating the derivative at the future time
This is called the backward, or implicit, Euler’s method
For this case, regardless of the size of the step, | yi| → 0 as i → ∞ .
Hence, the approach is called unconditionally stable.
Thai Minh Quan - Numerical Methods 24
Euler’s method
Example
Use both the explicit and implicit Euler methods to solve
where y(0) = 0.
(a)Use the explicit Euler with step sizes of 0.0005 and 0.0015 to solve
for y between t = 0 and 0.006.
(b)Use the implicit Euler with a step size of 0.05 to solve for y
between 0 and 0.4.
Thai Minh Quan - Numerical Methods 25
Euler’s method
Example
For this problem, the explicit Euler’s method is
the implicit Euler’s method is
Thai Minh Quan - Numerical Methods 26
Euler’s method
Example
For this problem, the explicit Euler’s method is
Thai Minh Quan - Numerical Methods 27
Euler’s method
Example
For this problem, the implicit Euler’s method is
Thai Minh Quan - Numerical Methods 28
Euler’s method
Example
For this problem, the implicit Euler’s method is
Thai Minh Quan - Numerical Methods 29
Euler’s method
Use the explicit Euler with step sizes of 0.1 to solve for y between
t = 0 and 1.
Thai Minh Quan - Numerical Methods 30
Euler’s method
Thai Minh Quan - Numerical Methods 31
Project
• Introduction
The objective of this project is to determine the Heat Transfer through a wall by
conduction using the heat equation:
T 2T 2T 2T
cp 2 2 2
t x y z
Thai Minh Quan - Numerical Methods 32
Project
• Project
Let a bar of length L, consisting of a homogeneous and isotropic material. We suppose
that The bar is perfectly insulated with the exception of the ends. The thermal
properties of material will be taken constant
The 1D-equation describe the thermal
transfers in this bar:
Where / c p is called the thermal diffusivity.
Thai Minh Quan - Numerical Methods 33
Project
To obtain the temperature filed in the bar, we define the following
mesh: the bar is "cut" in M intervals of length Δx. Temperatures are
calculated at different separate times by an interval Δt. The
temperature T(xi, tn) is denoted . We choose to define the coordinates
spatial and temporal as well:
Thai Minh Quan - Numerical Methods 34
Project
Thai Minh Quan - Numerical Methods 35
Differentiation
T Ti n 1 Ti n
t t
Thai Minh Quan - Numerical Methods 36
? Differentiation
2T
express the right term of equation (*): 2
x
2T Ti n1 2Ti n Ti n1
2
x x 2
Thai Minh Quan - Numerical Methods 37
Matlab
Question 3
Thai Minh Quan - Numerical Methods 38
Euler’s method
Matlab
Thai Minh Quan - Numerical Methods 39
Euler’s method
Matlab
dydt=@(t,y) 4*exp(0.8*t) - 0.5*y;
[t,y] = eulode(dydt,[0 4],2,1);
disp([t,y])
plot([t,y])
Thai Minh Quan - Numerical Methods 40
Euler’s method
Matlab
this error can be
reduced by using a
smaller step size.
Thai Minh Quan - Numerical Methods 41
Matlab
ODE Solvers in Matlab
Thai Minh Quan - Numerical Methods 42
Matlab
Solve the ODE:
y’ = 2t
Use a time interval of [0,5] and the initial condition y0 = 0.
Thai Minh Quan - Numerical Methods 43
Matlab
Thai Minh Quan - Numerical Methods 44
Euler’s method
Thai Minh Quan - Numerical Methods 45
Runge-Kutta methods
Thai Minh Quan - Numerical Methods 46
Runge-Kutta methods
Runge-Kutta (RK) methods achieve the accuracy of a Taylor series approach
without requiring the calculation of higher derivatives. Many variations exist but all
can be cast in the generalized form
Thai Minh Quan - Numerical Methods 47
Runge-Kutta methods
Thai Minh Quan - Numerical Methods 48
Runge-Kutta methods
The second-order version
With
Thai Minh Quan - Numerical Methods 49
Runge-Kutta methods
The second-order version
With
Thai Minh Quan - Numerical Methods 50
Runge-Kutta methods
The fourth-order version
Thai Minh Quan - Numerical Methods 51
Runge-Kutta methods
Case study
Formula:
Thai Minh Quan - Numerical Methods 52
Runge-Kutta methods
Case study
Thai Minh Quan - Numerical Methods 53
Runge-Kutta methods
Case study
Thai Minh Quan - Numerical Methods 54
Runge-Kutta methods
Case study
Thai Minh Quan - Numerical Methods 55
Runge-Kutta methods
Case study
Thai Minh Quan - Numerical Methods 56
Runge-Kutta methods
Case study
Thai Minh Quan - Numerical Methods 57
Runge-Kutta methods
All this can be done by using Matlab:
Thai Minh Quan - Numerical Methods 58
Runge-Kutta methods
Thai Minh Quan - Numerical Methods 59
Runge-Kutta methods
Thai Minh Quan - Numerical Methods 60
Runge-Kutta methods
Thai Minh Quan - Numerical Methods 61
Runge-Kutta methods
Thai Minh Quan - Numerical Methods 62
Runge-Kutta methods
Example
Thai Minh Quan - Numerical Methods 63
Runge-Kutta methods
Example
Thai Minh Quan - Numerical Methods 64
Runge-Kutta methods
Example
Thai Minh Quan - Numerical Methods 65