# Ordinary Differential Equations

## Presentation on theme: "Ordinary Differential Equations"— Presentation transcript:

Ordinary Differential Equations
Jyun-Ming Chen

Contents Review Euler’s method 2nd order methods Runge-Kutta Method
Midpoint Heun’s Runge-Kutta Method Systems of ODE Stability Issue Implicit Methods Adaptive Stepsize

Review DE (Differential Equation)
An equation specifying the relations among the rate change (derivatives) of variables ODE (Ordinary DE) vs. PDE (Partial DE) The number of independent variables involved

Solution of DE vs. Solution of Equation
Review (cont) Solution of DE vs. Solution of Equation Solution of an equation: Geometrically, f(x) x

Need additional conditions to specify a solution
Review (cont) Solution of an differential equation: Geometrically: t x

Review (cont) Order of an ODE
The highest derivative in the equation nth order ODE requires n conditions to specify the solution IVP (initial value problem): All conditions specified at the same (initial) point BVP (boundary value problem): otherwise

IVP VS. BVP Revisit Shooting Problem

IVP vs. BVP Physical meaning

Maxima on ODE Ode2: solves 1st and 2nd order ODE
Ic1, ic2, bc: setting conditions ‘ do not evaluate Maxima on ODE

Linear ODE Linearity: nth order linear ODE
Involves no product nor nonlinear functions of y and its derivatives nth order linear ODE

Focus of This Chapter Solve IVP of nth order ODE numerically e.g.,

ODE (IVP) First order ODE (canonical form)
Every nth order ODE can be converted to n first order ODEs in the following method:

Example

End of Review

The Canonical Problem This is Euler’s method

Example Compare with exact sol:

Example (cont) 1 x y y=e–x

Error Analysis (Geometric Interpretation)
Think in terms of Taylor’s expansion If the true solution were a straight line, then Euler is exact

Error Analysis (From Taylor’s Expansion)
Euler’s Euler’s truncation error O(Dx2) per step 1st order method

Cumulative Error y x Remark: Dx Error  But computation time x = 0
x = T Number of steps = T/Dx Cumulative Err. = (T/Dx)  O(Dx2) = O(Dx)

Example (Euler’s)

Methods Improving Euler
Motivated by Geometric Interpretation

Midpoint Method

Example (Midpoint)

Heun’s Method

Note the result is the same as Midpoint!?
Example (Heun’s) Note the result is the same as Midpoint!?

Remark Comparison of Euler, Heun, midpoint “order”:
1st order: Euler 2nd order: Heun, midpoint “order”: All are special cases of RK (Runge-Kutta) methods Exact Euler (error) Midpoint (error) y(0.1) 0.905 0.9 (0.005) (0) y(0.2) 0.819 0.81 (0.009) y(0.3) 0.741 0.729 (0.012)

RK Methods

RK Methods (cont)

Taylor’s Expansion

RK 1st Order

RK 2nd Order

RK 2nd Order (cont)

RK 4th Order Mostly commonly used one
Higher order … more evaluation, but less gain on accuracy Classical 4th order RK

Classical 4th order RK

System of ODE Convert higher order ODE to 1st order ODEs
All methods equally apply, in vector form

Example (Mass-Spring-Damper System)
Governing Equation After setting the initial conditions x(0) and x’(0), compute the position and velocity of the mass for any t > 0 c k Initial Condition x m

Example (cont)

Example (cont) set Dt=0.1 Assume m=1,c=1, k=1
(for ease of computation) set Dt=0.1

Stability: Symptom

Symptom: Unstable Spring System
Become unstable instantly … Start with this … Cause by stiff (k=4000) springs

Stability (cont) Example Problem: Conditionally stable

Discussion Different algorithm different stability limit
Check Midpoint Method Different problem different stability limit use the previous problem as benchmark

Review: Numerical Differentiation
Taylor’s expansion: Forward difference Backward difference

Numerical Difference (cont)
Central difference

Implicit Method (Backward Euler)
Forward difference Backward difference

Example Remark: Always stable (for this problem)
Truncation error the same as Euler (only improve the stability)

Stiff Set of ODE Use the change of variable
Get the following solution: Stability limit A stiff equation is a differential equation for which certain numerical methods for solving the equation are numerically unstable, unless the step size is taken to be extremely small

Linear System of ODE with Constant Coefficients
Do not really use (..)-1. Solve linear system instead

Analysis Explicit and implicit Euler both in the form:
represent x(0) in eigen basis x will converge if |li|  1

Analysis (cont) Stiff equations have large eigenvalues
Explicit Euler requires small h to converge Implicit Euler always converges (in this problem)

Example Explicit Implicit

Semi-Implicit Euler Not guaranteed to be stable, but usually is
Solving implicit methods by linearization is called a “semi-implicit” method Semi-Implicit Euler Not guaranteed to be stable, but usually is Jacobian

c k Initial Condition x m Implicit Euler

c k Initial Condition x m Semi-Implicit Euler

Ex: Semi-Implicit Euler

Amazingly, this translates to…
Very similar to Verlet integration formula… no wonder Verlet is pretty stable

Adaptive Stepsize Solving ODE numerically … tracing the integral curve y(x) what’s wrong with uniform step size Uniformly small: waste effort Uniformly large: might miss details

Step Doubling Idea: Estimate the truncation error by taking each step twice: one full step, two half steps control the step size such that the estimated error is not too big. 1(2h1) 2(h1) Desired h0

Ex: RK 2nd Order Overhead: # of f(x,y) evaluations 24–2 = 6

GSL

Initialization

Iteration