You are on page 1of 24

CE 205: Numerical Methods

Ordinary
O di Diff
Differential
ti l
Equations

CE 205: Numerical Methods Dr. Tanvir Ahmed


Why study Differential Equations?
Many physical phenomena are best formulated 
mathematically in terms of their rate of change.
mathematically in terms of their rate of change.

Motion of a swinging pendulum
d 2θ g
2
+ sin θ = 0
dt l
Bungee‐jumper 
j
Equation
dv cd 2
= g− v
dt m

CE 205: Numerical Methods Dr. Tanvir Ahmed


ODE and Engineering practice
F = ma Physical Laws

dv
d cd 2
= g− v ODE
dt m
Analytical Numerical

⎛ gc ⎞ ⎡ 2⎤
Solution
v(ti +1 ) = v(ti ) + ⎢ g − d v(ti ) ⎥ (ti +1 − ti )
gm c
v(t) = tanh⎜ d
t⎟
cd ⎝ m ⎠ ⎣ m ⎦

Independent variable: spatial or temporal
CE 205: Numerical Methods Dr. Tanvir Ahmed
Initial value and boundary value problems
Boundary Value problems: Solve

General Solution
Applying B.C.

Initial Value problems: Solve
General Solution

Applying I.C.
l

CE 205: Numerical Methods Dr. Tanvir Ahmed


Solving initial value problems
dy
ODE of the form = f (t, y)
will be solved using the one‐
dt
step methods having the general form:
step methods having the general form: 
yi+1 = yi + φh
φ is called an increment function, and 
is used to extrapolate from an old 
is used to  from an old
value yi to a new value yi+1

Techniques:
‐ Euler
‐ Heun
‐ Midpoint
Fourth‐Order
‐ Fourth Runge‐Kutta
Order Runge Kutta
CE 205: Numerical Methods Dr. Tanvir Ahmed
Euler’s Method
The first derivative provides a direct estimate of the 
slope at ti:
slope at t
dy
= f (t i , yi )
dt ti

Euler method uses that 
Euler method uses that
estimate as the increment 
function: 

φ = f (t i , yi )
yi+1 = yi + f (t i , yi )h

CE 205: Numerical Methods Dr. Tanvir Ahmed


Errors in ODE

The numerical solution of ODEs involves two types of 
yp
error:
‐ Truncation errors, caused by the nature of the techniques employed
‐Roundoff
Roundoff errors, caused by the limited numbers of significant digits that can 
errors caused by the limited numbers of significant digits that can
be retained

The total, or global truncation error can be further split 
into:
‐ local truncation error that results from an application method in question 
over a single step, and 
‐ propagated truncation error that results from the approximations 
produced during previous steps.

CE 205: Numerical Methods Dr. Tanvir Ahmed


Error Analysis in Euler’s Method
The local truncation error for Euler’s method is O(h2) and 
proportional to the derivative of f(t,y) while the global 
truncation error is O(h).
i i (h)

Global error can be reduced by decreasing the step size
CE 205: Numerical Methods Dr. Tanvir Ahmed
Improvement of Euler’s Method
Main limitation: the derivative at the beginning of the 
interval is assumed to apply across the entire interval

Two modifications can be made:
(1) Heun’s method
(2) Mid‐point method
CE 205: Numerical Methods Dr. Tanvir Ahmed
Heun’s Method (Predictor‐corrector approach)
Determine derivatives at the beginning and predicted 
ending of the interval and average them to obtain an 
i
improved estimate of the slope
d i f h l

Predictor: yi0+1 = yi + f (ti , yi )h


f (ti , yi ) + f (ti +1 , yi0+1 )
Corrector: yi +1 = yi + h
2
CE 205: Numerical Methods Dr. Tanvir Ahmed
Heun’s Method (Predictor‐corrector approach)
predictor‐corrector approach can be iterated to 
convergence:

CE 205: Numerical Methods Dr. Tanvir Ahmed


Midpoint Method
Similar to Heun’s method, but predicts the slope at the 
midpoint of an interval rather than at the end

yi +1/ 2 = yi + f (ti , yi )h / 2 local truncation error  O(h3) 


yi +1 = yi + f (ti +1/ 2 , yi +1/ 2 )h ( 2)
gglobal error  O(h

CE 205: Numerical Methods Dr. Tanvir Ahmed


Runge‐Kutta Methods: general form
Can achieve the accuracy of a Taylor series approach 
without requiring the calculation of higher derivatives.

The increment function φ can be generally written as
φ = a1k1 + a2 k2 +L+ an kn

k1 = f (t i , yi )
k2 = f (t i + p1h, yi + q11k1h)
k3 = f (t i + p2 h, yi + q21k1h + q22 k2 h)
M
kn = f (t i + pn−1h,
h yi + qn−1,1k1h + qn−1,2 k2 h +L+ qn−1,n−1kn−1h)

a’s, p’s
, p and q’s
q are constants

CE 205: Numerical Methods Dr. Tanvir Ahmed


4th order Runge‐Kutta method
The most popularly used method
1
yi+1 = yi + (k1 + 2k2 + 2k3 + k4 )h
6

where
k1 = f (t i , yi )
⎛ 1 1 ⎞
k2 = f ⎜t i + h, h yi + k1h ⎟
⎝ 2 2 ⎠
⎛ 1 1 ⎞
k3 = f ⎜t i + h, h yi + k2 h ⎟
⎝ 2 2 ⎠
k4 = f (t i + h, yi + k3h)

CE 205: Numerical Methods Dr. Tanvir Ahmed


Performance of different methods

CE 205: Numerical Methods Dr. Tanvir Ahmed


A system of ODE
dy1
= f1 (t, y1 , y2 ,L, yn )
dt
dy2
= f2 (t, y1 , y2 ,L, yn )
dt
M
dyn
= fn (t, y1 , y2 ,L, yn )
dt

n initial conditions be known at the starting value of t.

One‐step method is applied for every equation at each 
step before proceeding to the next step
step before proceeding to the next step
‐Euler’s method
‐4th order R‐K

CE 205: Numerical Methods Dr. Tanvir Ahmed


Adaptive solution methods
The solutions to some ODE 
problems exhibit multiple time
problems exhibit multiple time 
scales ‐ for some parts of the 
solution the variable changes
solution the variable changes 
slowly, while for others there are 
abrupt changes.

Adaptive algorithms can 
change step‐size depending 
on the region
‐Step‐halving
S h l i
‐Performing two RK predictions of 
different order

CE 205: Numerical Methods Dr. Tanvir Ahmed


Boundary value problems

Conditions are not 
C di i
known at a single point 
but rather are given at
but rather are given at 
different values of the 
independent variable
independent variable

Boundary Conditions:
y
‐values of variables
‐values of derivatives of variables

CE 205: Numerical Methods Dr. Tanvir Ahmed


Example: Boundary value problem
Non‐insulated rod positioned between bodies of constant 
i l d d ii db b di f
but different temperature

d 2T
2
+ h′(T∞ − T ) = 0
dx

Bo ndar conditions
Boundary conditions: T (0) = T1 = 40, T ( L) = T2 = 200

L = 10m Ta = 20 h′ = 0.01m −2

Analytical solution:

CE 205: Numerical Methods Dr. Tanvir Ahmed


Numerical solution: the shooting method
the boundary‐value problem is converted into an 
equivalent initial‐value problem.
q p
⎧ dT
2
⎪ = z
d T
+ h′(T∞ − T ) = 0 ⇒ ⎨
dx
= − h′(T∞ − T )
dx 2 dz

⎩ dx
Generally, the equivalent system will not have sufficient 
G ll th i l t t ill t h ffi i t
initial conditions 
‐ A guess is made for any undefined values.
A guess is made for any undefined values
‐ The guesses are changed until the final solution satisfies all the B.C. 

FFor linear ODEs, only two “shots” are required ‐
li ODE l t “h t” i d the 
th
proper initial condition can be obtained as a linear 
interpolation of the two guesses
interpolation of the two guesses.
CE 205: Numerical Methods Dr. Tanvir Ahmed
Numerical solution: the shooting method
Solution using RK method:

CE 205: Numerical Methods Dr. Tanvir Ahmed


Numerical solution: finite difference
finite differences are substituted for the derivatives in 
the original equation
g q
d 2T
2
+ h′(T∞ − T ) = 0
dx

d 2T Ti−1 − 2Ti + Ti+1


=
dx 2
Δx 2
Ti−1 − 2Ti + Ti+1
+ h′(T∞ − Ti ) = 0
Δx 2

−Ti−1 + (2 + h′Δx 2 )Ti − Ti+1 = h′Δx 2T∞


CE 205: Numerical Methods Dr. Tanvir Ahmed
Numerical solution: finite difference
The linear differential equation is transformed into a set 
of simultaneous algebraic equations.

Since T0 and Tn are known (Drichlet boundary conditions), 


they will be on the right hand side of the linear algebra
they will be on the right‐hand‐side of the linear algebra 
system

⎡2 + h′Δx 2 −1 ⎤⎧ T ⎫ ⎧h′Δx 2T∞ + T0 ⎫


⎢ −11 2 + h′Δx 2 −1
1 ⎥⎪ T1 ⎪ ⎪⎪ h′Δx 2T ⎪⎪
⎢ ⎥⎨ 2 ⎬ = ⎨ ∞

⎢ O O O ⎥⎪ M ⎪ ⎪ M ⎪
⎢⎣ −1
1 2 + h′Δx 2 ⎥⎦⎩Tnn−11 ⎭ ⎪⎩h′Δx 2T∞ + Tn ⎪⎭

CE 205: Numerical Methods Dr. Tanvir Ahmed


Numerical solution: finite difference
If there is a derivative boundary condition (Neumann 
B.C.), the centered difference equation is solved at the 
point and rewriting the system equation accordingly.
For a Neumann condition at  T0  point:

dT T1 − T−11 ⎛ dT ⎞
= ⇒ T−1 = T1 − 2Δx
2Δ ⎜ ⎟
dx 0 2Δx ⎝ dx 0 ⎠
T−1 + (2 + h′Δx 2 )T0 − T1 = h′Δx 2T∞
−T
⎡ ⎛ dT ⎞⎤
−⎢T1 − 2Δx⎜ ⎟ (
⎥ + + ′Δx ) − = ′Δx
2 2
2 h T0 T1 h T∞
⎣ ⎝ dx
d 0 ⎠⎦
⎛ dT ⎞
(2 + h′Δx )T0 − 2T1 = h′Δx T∞ − 2Δx⎜⎝ dx ⎟⎠
2 2

0
CE 205: Numerical Methods Dr. Tanvir Ahmed

You might also like