Documente Academic
Documente Profesional
Documente Cultură
Ch. 25
Orientation
• ODE’s
– Motivation
– Mathematical Background
• Runge-Kutta Methods
– Euler’s Method
– Huen and Midpoint methods
Lesson Objectives
• Be able to classify ODE’s and distinguish ODE’s from
PDE’s.
• Be able to reduce nth order ODE’s to a system of first
order ODE’s.
• Understand the visual representations of Euler’s method.
• Know the relationship of Euler’s Method to the Taylor
series expansion and the insight it provides regarding the
error of the method
• Understand the difference between local and global
truncation errors for Euler’s method.
1
Ordinary Differential Equations: Motivation
∂ 2T ∂ 2T
+ =0
∂x 2 ∂y 2
∂u ∂u
u +v = F (t )
∂x ∂y
2
Ordinary Differential Equations
• Reducing higher order differential equations
to a system of first order equations:
mx’’ + cx’ + kx = 0
Define a new variable
dx
y=
dt
Substitute into the original DE
my’ + cy + kx = 0
dx
y=
my’ + cy + kx = 0 dt
dy ⎛ cy + kx ⎞
= −⎜ ⎟=0
dt ⎝ m ⎠
In general, an nth order ODE can be reduced
to n 1st order ODEs (with appropriate
boundary or initial conditions)
3
Answer the following
• What is (are) the dependent variable(s)?
• What is (are) the independent variable (s)?
• Is this a ODE or PDE?
• What order is this differential equation?
• Is this linear or nonlinear?
dC d2C
=
dt dx2
Leonhard Euler
y = f (x)
Runge-Kutta Methods – CH 25
Solve ODEs of the form: y
yi +1 = yi + φh
dy error
= f ( x, y )
dx
Can be solved Numerically using: yi
yi +1 = yi + φh
φ = slope estimate xi xi+1 x
h = step size h
yi = current value of the dependant variable
yi+1 estimate of dependant variable over dist. H
Formula can be applied step by step to trace out the
solution trajectory.
4
Euler’s Method
Truncation RO Error
Error
Number of steps
5
Euler’s Method – Error Assessment
Local Truncation Error:
f n −1 ( xi , yi )h n
yi +1 = yi + f ( xi , yi )h +
f ' ( xi , yi )h 2
2!
+ ... +
n!
( )
+ O h n +1
∴ Ea = O h2 ( ) Local truncation
Error
6
We have learned
– How to classify differential equations
– How to reduce nth order ODE’s to a system of
1st order ODE’s.
– The visual representation of Euler’s method.
– The relationship between the Taylor series
expansion and Euler’s Method
– The difference between global and local
truncation error in Euler’s Method.
7
Euler’s Method – Stability
• A numerical method is unstable if the error grows without bound
(e.g. exponential growth) for a problem in which the exact solution
is bounded.
• Can depend on the method as well as the differential equation.
• Example:
dy
= λy
dx
y = y 0 e λx
y i + 1 = y i + λ y i h = y i (1 + λ h )
y 1 = y 0 (1 + λ h )
Euler
y 2 = y 1 (1 + λ h ) = y 0 (1 + λ h )(1 + λ h ) = y 0 (1 + λ h )
2
Method
y n = y 0 (1 + λ h )
n
1 + λh ≤ 1
This Implies
λ < 0
2
h ≤
λ
8
Huen’s Method – “Predictor – Corrector” Approach
Slope 2
y f(xi+1,yoi+1)
Predictor Step
Slope 1
f(xi,yi)
xi xi+1 x
y
Average Slope
f ( xi , yi ) + f ( xi +1 , yio+1 )
yi +1 = yi + h
2
Corrector Step
Use average slope to
Obtain new estimate
xi xi+1 x
f ( x i , y i ) + f ( x i + 1 , y io+ 1 )
y' =
2
f ( xi , yi ) + f ( xi +1 , yio+1 )
yi +1 = yi + h
2
Note:
•This iterative procedure does not converge on the true answer
•Converges to a finite truncation error
9
Huen’s Method – Example
Solve: y'= x − y Subject to the I.C. y ( x = 0 ) = 0
at x=0.4 with h=0.4 using Heun’s method
−x
Exact Solution: y e = x + e − 1
At x = 0.4 y e = 0 . 4 + e − 0 . 4 − 1 = 0 . 07032
.07032 − .08
True Error Et = • 100% = 13%
.07032
.07032 − .08
True Error Et = • 100% = 13%
.07032
Directly related
f ( xi ) + f ( xi +1 )
yi +1 = yi + h to the
trapezoidal rule
2
10
Runge-Kutta Methods – CH 25
Can achieve Taylor Series accuracy without evaluating higher
order derivatives.
Runge-Kutta Methods – CH 25
Can achieve Taylor Series accuracy without evaluating higher
order derivatives.
Runge-Kutta Methods
To Determine the final form of (1)
1. Select n
11
See Box
25.1 in
2nd- Order Runge-Kutta Methods Text
General Form: y
i +1 = yi + (a1k1 + a2 k 2 )h (2)
k1 = f ( xi , yi )
k 2 = f ( xi + p1h, yi + q11k1h)
By setting (2) equal to a T-S expansion through the 2nd order
term, we can solve for a1,a2,p1,q11
a1 + a2 = 1 a1 = 1 − a2
a2 p1 = 1 / 2
3 Eqns & 4 unknows p1 = 1 / (2a2 )
Specify a2 value
a2 q11 = 1 / 2 q11 = 1 / (2a2 )
*Since there are an infinite number of choices for a2 there will be
an infinite number of 2nd order R-K Methods
q11 = 1 / (2a2 )
Global Truncation Error ~ O(h2)
yi +1 = yi + k 2 h
k1 = f ( xi , yi )
k 2 = f ( xi + 0.5h, yi + 0.5k1h)
a1 = 1 − a2
p1 = 1 / (2a2 )
q11 = 1 / (2a2 )
Global Truncation Error ~ O(h2)
12
2nd- Order Runge-Kutta Methods
C) Ralston’s Method (a2 = 2/3 ): a1 = 1/3 , p1 = 3/4, q11 =3/4
⎛1 2 ⎞
yi +1 = yi + ⎜ k1 + k 2 ⎟h
⎝3 3 ⎠
k1 = f ( xi , yi )
k 2 = f ( xi + 0.75h, yi + .75k1h)
a1 = 1 − a2
p1 = 1 / (2a2 )
q11 = 1 / (2a2 )
Global Truncation Error ~ O(h2)
k 2 = f ( xi + 0.5h, yi + .5k1h) k1 φ
k3
k4
k3 = f ( xi + 0.5h, yi + .5k 2 h)
k 4 = f ( xi + h, yi + k3 h)
h
Global Truncation Error ~ O(h4) xi xi+1/2 xi+1
y1 = y0 +
1
(k1 + 2k 2 + 2k3 + k4 )h = 0 + 1 (0 + 2(.2) + 2(.16) + .336)0.4
6 6
y1 = 0.07040
13
4th - Order Runge-Kutta Methods –
Example: Use classical RK4 to determine y @ x=0.4 for y’=x-y and
h=0.4
Error:
.07032 − .07040
Et = • 100% = .11%
.07032
Method Comparison
Systems of Equations
• Recall, Any nth order ODE can be represented as a system
of n 1st order ODEs
= f1 (x, y1 , y2 ,..., yn )
dy1
dx
= f 2 (x, y1 , y2 ,..., yn )
dy2
dx
M
= f n (x, y1 , y2 ,..., yn )
dyn
dx
14
Systems of Equations – RK4 Example
= f1 ( x, y1 , y2 )
dy1
dx
= f 2 ( x, y1 , y2 )
dy2
dx
For example:
= f1 ( x, y, z ) = − y
dy
dx
= f 2 (x, y, z ) = 3 − 4 cos z + y
dz
dx
15
Systems of Equations – RK4 Example
y1,i +1 = y1i +
1
(k11 + 2k 21 + 2k31 + k41 )h
6
y2,i +1 = y2i + (k12 + 2k 22 + 2k32 + k 42 )h
1
6
dy1
= y2
dx y1 ( x = 0 ) = 4
dy2 y
= − 2 − 7 y1 y2 ( x = 0 ) = 0
dx 2
16