AE305 Chapter 2
AE305 Chapter 2
NUMERICAL SOLUTIONS OF
ORDINARY DIFFERENTIAL EQUATIONS
• Solutions of 1st order ODEs
• Euler’s method
• Improved Euler Method
• Runge Kutta (RK) Methods
• Adaptive stepping
• Stability of RK methods
• Solutions of 2nd and higher order ODEs
• Solutions of coupled ODEs
• Solutions of boundary value problems
İ.H. TUNCER & Y. ÖZYÖRÜK 21 AE305 - Numerical Methods in Aerospace Engineering @ 20201
Differential Equations
An equation which is composed of an unknown function and its derivatives with respect to
independent variables is called a differential equation .
• This is in contrast to a Partial Differential Equation, PDE that involves two or more
independent variables.
E.g. Unsteady heat diffusion through a 1-D bar :
∂T ∂2T
=α 2
∂t ∂x
İ.H. TUNCER & Y. ÖZYÖRÜK 22 AE305 - Numerical Methods in Aerospace Engineering @ 20201
Second-order examples
d 2x dx
Mass-spring-damper : m +c + kx = 0, m : mass, c : damping cons, k : spring cons
dt 2 dt
2 2
∂ y ∂ y
Wave equation for a string : − a2 2 = 0, y : discplacement, a : wave speed
∂t 2 ∂x
İ.H. TUNCER & Y. ÖZYÖRÜK 23 AE305 - Numerical Methods in Aerospace Engineering @ 20201
Solution of ODEs - Boundary Conditions
For the solution of an nth order ordinary differential equation, n conditions are required to
obtain a unique solution.
• If all the conditions are specified at the beginning of the solution domain, then the
problem is called an initial-value problem, IVP .
2
m ddt x2 + c dx
dt + kx = 0 2nd-order ODE
Conditions:
x|t=0 = x0 −→ IC #1
dx
dt |t=0 = v0 −→ IC #2
(illustration : wiki)
• In boundary-value problems, BVP, the conditions are specified at both ends of the
solution domain.
2
Equation : ddxT2 + kq̇ = 0 2nd-order ODE
Boundary Conditions:
T |x=0 = T0 −→ BC #1
−k dT |
dx x=L
= qL00 −→ BC #2
İ.H. TUNCER & Y. ÖZYÖRÜK 24 AE305 - Numerical Methods in Aerospace Engineering @ 20201
• Numerical solutions can only be obtained for discrete values of the independent variables
• Consider a function y (x), where x is the spatial coordinate. y is the dependent variable,
and x is the independent variable.
• Then, treating the problem numerically requires discretization of the independent variable
first, and assigning indices to the discrete points.
İ.H. TUNCER & Y. ÖZYÖRÜK 25 AE305 - Numerical Methods in Aerospace Engineering @ 20201
• Numerical methods to solve an initial value problem is based on the first order Taylor
Series Expansion, which is known as Euler’s method :
dy
y (x + ∆x) = y (x) + ∆x + O(∆x 2 )
dx (x,y )
y (x + ∆x) = y (x) + ∆x y 0 (x, y )
y (x + ∆x) = y (x) + ∆x f (x, y )
yi+1 = yi + ∆x f (xi , yi )
İ.H. TUNCER & Y. ÖZYÖRÜK 27 AE305 - Numerical Methods in Aerospace Engineering @ 20201
• If the initial condition for the velocity is given at time t1 , the velocity of the object at a
later time t2 = t1 + ∆t. The new value is in turn employed to extend the computation to
the next time step t3 = t2 + ∆t and so on.
NewValue = OldValue + StepSize × Slope
= OldValue + StepSize × ODE
time step # time velocity update
n =1 t = t1 v = v 1 Initial condition
n =2 t2 = t1 + ∆t v 2 = v 1 + ∆t g − mc v 1
n =3 t3 = t2 + ∆t v 3 = v 2 + ∆t g − mc v 2
n =4 t4 = t3 + ∆t v 4 = v 3 + ∆t g − mc v 3
... ... ...
n tn = tn−1 + ∆t v n = v n−1 + ∆t g − mc v n−1
n+1 n c n
n+1 tn+1 = tn + ∆t v = v + ∆t g − m v
• Note that the slope in Euler method is evaluated at the beginning of the interval, which does not
represent the average slope over the interval!
İ.H. TUNCER & Y. ÖZYÖRÜK 28 AE305 - Numerical Methods in Aerospace Engineering @ 20201
!−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
! . . A SIMPLE EULER SOLVER f o r ODEs ! . . Solution loop
! . . AE305 − N u m e r i c a l Methods do w h i l e ( time . l t . finaltime )
!−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− time = time + stepsize
Module f r e e _ f a l l i n g _ b o d y _ d a t a velocity = velocity + ODE ( velocity )∗stepsize
grav = 9 . 8 1 w r i t e ( 1 , ” ( 2 f 1 2 . 3 ) ” ) time , velocity
fric = 1 2 . 5 enddo
xmass = 7 0 .
End module ! . . Close the output file
close (1)
Program EULER
c h a r a c t e r ∗40 fname ! . . P l o t t h e s o l u t i o n w i t h ” x g r a p h ” , ” xmgr ” o r ” g n u p l o t ” on←-
L i n u x X−windows
! . . Read t h e s t e p s i z e ! c a l l SYSTEM( ” xg v e l o c i t y . d a t &”)
p r i n t ∗,” ” ! c a l l SYSTEM( ” xmgr v e l o c i t y . d a t &”)
p r i n t ∗, ” E n t e r S t e p S i z e and F i n a l T i m e :> ” ! c a l l SYSTEM( ” g n u p l o t p l o t . g p l ” )
r e a d (∗ ,∗) stepsize , finaltime
stop
! . . open t h e o u t p u t f i l e End
p r i n t ∗ , ” E n t e r t h e o u t p u t f i l e name [ v e l o c i t y . d a t ] : ”
r e a d (∗ , ” ( a ) ” ) fname !−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
i f ( fname . eq . ” ” ) fname = ” v e l o c i t y . d a t ” ! . . D e f i n e t h e ODE a s a f u n c t i o n
open ( 1 , f i l e =fname , form=” f o r m a t t e d ” ) F u n c t i o n ODE ( vel )
use free_falling_body_data
! . . S e t t h e I n i t i a l C o n d i t i o n s and o u t p u t them ODE = grav − fric / xmass ∗ vel
time = 0. return
velocity = 0 . End
w r i t e ( 1 , ” ( 2 f 1 2 . 3 ) ” ) time , velocity
İ.H. TUNCER & Y. ÖZYÖRÜK 29 AE305 - Numerical Methods in Aerospace Engineering @ 20201