You are on page 1of 19

Numerical Solution of Ordinary

Differentiation Equations
x2

x1
Differential Equations
 Differential equation describes the relation
between an unknown function and its
derivatives

 Solving a differential equation is to find a


function that satisfies the relation

 Numerical solution of differential equations is


based on finite-dimensional approximation

Numerical Methods © Wen-Chieh Lin 2


Ordinary Differential Equations
 Ordinary differential equation (ODE)
 All derivatives are with respect to single
independent variable, usually representing time
Known function
dx
f ( x(t )) f ( x, t )
dt
Unknown function
Time derivative of that evaluates the
the unknown function state given time
x(t0 ) : state vector at time t0
*We’ ll show that a higher ODE can be transformed into
this 1st order system soon!
Numerical Methods © Wen-Chieh Lin 3
Visualizing Ordinary Differential Equation

dx
x f (x, t ) x2
dt
x(t ) : a moving point

f ( x, t ) : x' s velocities

x1

Numerical Methods © Wen-Chieh Lin 4


Vector Field
 Thedifferential equation xf ( x, t ) defines
a vector field over x
x2

Think of this vector field as


the sea, and the velocity of
current at different places
and time is defined by f(x,t)
x1

Numerical Methods © Wen-Chieh Lin 5


Integral Curves
 Pick a starting point, and follow the vectors

x2

Release a ball at any


starting point and let it drift
following the current. The
trajectory swept out by the
ball is an integral curve
x1

Numerical Methods © Wen-Chieh Lin 6


Initial Value Problem
Given xf ( x, t ) and x 0 x(t0 ), find x(t )
 Given the starting point, follow the integral
curve x2

Where the ball is carried


depends on where we
initially drop it, but once
dropped, all future motion
is determined by f(x,t)
x1

Numerical Methods © Wen-Chieh Lin 7


Numerical Solution of ODEs
 Instead of true integral curve, numerical solution
follow a polygonal path
 Each leg is obtained by evaluating the derivative
at discrete time steps x2

 Bigger steps, bigger errors

x1

Numerical Methods © Wen-Chieh Lin 8


Problem I: Inaccuracy

 Error turns x(t) from a circle into the spiral of


your choice!
x2

x1

Numerical Methods © Wen-Chieh Lin 9


Problem II: Instability

x2

x1

Numerical Methods © Wen-Chieh Lin 10


Euler’
s Method
 Simplest numerical solution method
 Bigger time steps, bigger errors
x2
x(t t ) x(t ) t f ( x, t )

x1

Numerical Methods © Wen-Chieh Lin 11


Euler’
s Method (cont.)
Given xf ( x, t ) and x 0 x(t0 ), find x(t )
 Solves ODE using one-term Taylor-series
h2
x(t0 h ) x(t0 ) hx(t0 )   x()
2
xf ( x, t )
x 0 x(t0 )
x(t t ) x(t ) t f ( x, t )
x n 1 x n hx
n
Numerical Methods © Wen-Chieh Lin 12
Drawbacks of Euler’
s Method
 Inaccuracy

 Inefficiency
 Need to use small time-steps to avoid divergence
 Example:
http://www.cse.uiuc.edu/iem/ode/eulrmthd/

 Improvement using the midpoint method


 Slope at midpoint is used

Numerical Methods © Wen-Chieh Lin 13


The Midpoint Method
 Compute an Euler step
x t f ( x(t0 ))
 Evaluate f at the midpoint x2

x
f mid f ( x(t0 )  )
2
 Take a step using the
midpoint value
x(t0 t ) x(t0 ) t f mid x1

Numerical Methods © Wen-Chieh Lin 14


The Midpoint Method (cont.)
 Solves ODE using two-term Taylor-series
2 2
h h
x(t0 h ) x(t0 ) hx
(t0 )   x(t0 )   x
()
2 3
d d dx
x x f ( x(t )) f ' (x )
 f ' ( x ) f ( x )
dt dt dt
 Approximating f’ by Taylor-series
f ( x 0 x ) f ( x 0 ) xf ' ( x 0 ) h
x  f (x 0 )
2
h h h
f (x 0  f (x 0 )) f (x 0 )  f (x 0 ) f ' (x 0 ) f (x 0 )  x
0
2 2 2
Numerical Methods © Wen-Chieh Lin 15
The Midpoint Method (cont.)
h h
f ( x 0  f ( x 0 )) f ( x 0 )  x
0
2 2
 
2
h h
x 0 h f ( x 0  f ( x 0 )) f ( x 0 )

2  2 
2 2
h h
x(t0 h ) x(t0 ) hx (t0 )   (t0 )  
x x
()
2 3
 h 
x(t0 ) hf (x 0 ) h f (x 0  f (x 0 )) f (x 0 )O (h 3 )
 2 
h
x(t0 ) hf (x 0  f (x 0 )) O (h ) 3

2 Numerical Methods © Wen-Chieh Lin 16


Higher-Order ODEs
 Orderof ODE determined by highest-order
derivative of solution function appearing in
ODE

 Equationswith higher derivatives can be


transformed into equivalent first-order system

Numerical Methods © Wen-Chieh Lin 17


Higher-Order ODEs (cont.)
 Given k-th order ODE
d (k ) y (k  ( k 2 )
f ( y , y
1)
,..., y ' , y , t )
dt
 Define  Original ODE equivalent to first
order system
x1 (t ) y
x '1   x2 
x2 (t ) y ' x '   
x
 2  3 
x3 (t ) y"     
   
x 'k 1   xk 
xk (t ) y ( k 1) 
 k  
x '   f ( y ( k 1)
,, y ' , y , t )

Numerical Methods © Wen-Chieh Lin 18
Take Home Message
 Visualization of ODE solution
x2

 Don’
t use Euler’
s method
 Inaccuracy

 Inefficiency (or unstable)

x1
 We’
ll introduce other more stable methods
next class
Numerical Methods © Wen-Chieh Lin 19

You might also like