Professional Documents
Culture Documents
8 ODEs PDF
8 ODEs PDF
Ordinary Differential
Equations
Engineering Computation
dv F
Newton's 2nd law:
=
dt m
dT
Fourier's heat law: q = k '
dx
dc
Fick's diffusion law j = D
dx
Faraday's law:
Engineering Computation
di
Vi = L
dt
d2 y
dx
+ 2 y = g(x)
dy
= f (y, t)
dt
2T
y
= c2
Engineering Computation
=0
2u
x
=0
Laplace Equation
Wave Equation u = u(x,t)
3
Auxiliary Conditions
Auxiliary Conditions
Because we are integrating an indefinite integral, we need
additional information to obtain a unique solution. Note that an
nth order equations generally requires n auxiliary conditions.
dy
= f (x, y)
dx
Engineering Computation
d2 y
dy
+
+ 5y = 0
2
dx
dx
dy
dz
+ z + 5y = 0
Let z =
& substitute
dx
dx
Now solve a SYSTEM of two linear, first order ordinary
differential equations:
dy
=z
dx
Engineering Computation
and
dz
= z 5y
dx
dy
= f (x, y)
dx
Engineering Computation
Predicted
True
xi
Engineering Computation
x i+1
Euler's Method
xi+1 = xi + h
Estimate the slope as i = f(xi,yi)
yi+1 = yi + f(xi,yi) h
y i+1 = yi + fi h
h2
= O (h 2 )
E a = yi+1 y i+1 = yi "
2
Ea = G(n,h) O (h2) = O (h)
10
a
x
xo x1
h
Matlab demo
Engineering Computation
11
Error Analysis
1. Truncation Error (Truncating Taylor Series)
[large step size large errors]
2. Rounding Error (Machine precision)
[very small step size roundoff errors]
Two kinds of Truncation Error:
12
Predict:
yi+1 o = yi + f(xi,yi)h
o
xi+1 = xi + h
f (x i , yi ) + f (x i+1 , yi+1 )
f =
2
yi+1 = yi + f h
13
a
x
xo x1
h
Matlab demo
Engineering Computation
14
h
2
Correct yi+1:
h
= xi +
2
yi+1 = yi + f(xi+1/2,yi+1/2) h
Matlab demo
Engineering Computation
15
16
k 2 = f x i + 12 h, yi + 12 hk1
yi+1 = yi + k2 h
same k1
17
where
k1 = f(xi , yi)
k2 = f(xi + h/2 , yi + k1h/2)
k3 = f(xi + h/2 , yi + k2h/2)
k4 = f(xi + h , yi + k3h)
Euler step
Midpoint
Better midpoint
Full step
18
dy
=y
dt
with solution
y(t) = y0 e t
2. Exponential decay
discharge of a capacitor,
decomposition of material in a river,
wash-out of chemicals in a reactor, and
radioactive decay
dy
= - y
dt
Engineering Computation
with solution
y(t) = y0 e - t
19
x
0.000
0.125
0.250
0.375
0.500
0.625
0.750
0.875
1.000
Exact
Solution
1.000
1.414
2.000
2.828
4.000
5.657
8.000
11.31
16.00
h=
Engineering Computation
Euler
1.000
1.347
1.813
2.442
3.288
4.427
5.962
8.028
10.81
0.125
Heun
w/o iter
1.000
4th-order
RungeKutta
1.000
1.933
3.738
3.945
7.227
13.97
0.25
15.56
0.5
h * ki
for R-K
1.386
2.347
3.013
5.564
5.469
9.260
11.89
21.95
20
Exact
Solution
1.0000
1.1892
1.4142
1.6818
2.0000
2.3784
2.8284
3.3636
4.0000
4.7568
5.6569
6.7272
8.0000
9.5137
11.314
13.454
16.000
h=
Engineering Computation
Euler
1.0000
1.1733
1.3766
1.6151
1.8950
2.2234
2.6087
3.0608
3.5911
4.2134
4.9436
5.8002
6.8053
7.9846
9.3683
10.992
12.896
0.0625
Heun
w/o iter
1.0000
4th-order
RungeKutta
1.4066
1.9786
1.9985
2.7832
3.9149
3.9940
5.5068
7.7460
7.9820
10.8958
15.326
15.952
0.125
0.25
h * ki
for R-K
0.6931
0.9334
1.0166
1.3978
1.3853
1.8653
2.0317
2.7935
2.7684
3.7279
4.0604
5.5829
5.5327
7.4502
8.1147
11.157
Matlab demo
21
Engineering Computation
22
y
v
v
d 1
2
v3
dx v 2
v
f
(x)
a(x)v
b(x)v
c(x)v
d(x)y
3
2
1
3
Engineering Computation
23
v1
dy / dx
dv / dx
v
2
1
=
dv 2 / dx
v3
dv
/
dx
f
(x)
a(x)v
b(x)v
c(x)v
d(x)y
3
2
1
3
Engineering Computation
24
d2x
dt
+ kx = P(t)
or
m = mass
k = spring constant
P(t) = forcing function = P sin(t)
i.e., harmonically driven
Engineering Computation
d2x
P(t)
+ x =
2
m
dt
2
k
=
= circular frequency
m
2
T=
= natural period
25
d2x
dt 2
Initial conditions:
+ 2 x =
P(t)
m
x(0) = 0 and
dx
(0) = 0
dt
Analytical solution:
x(t) =
P
2
m( )
sin(t) +
P
2
m( )
sin( t)
Engineering Computation
26
d2x
dt 2
+ 2 x =
P(t)
m
with x(0) = 0
dv P sin( t)
=
2 x = g(t, x, v)
dt
m
with v(0) = 0
Engineering Computation
27
d2x
dt 2
+ 2 x =
P(t)
m
dx
= v = f (t, x, v)
dt
dv P sin( t)
=
2 x = g(t, x, v)
dt
m
t0 = 0
x0 = 0
v0 = 0
t1 = t0 + h = 0.01
x1 = x0 + f(t0,x0,v0)h = 0
v1 = v0 + g(t0,x0,v0)h = 6.39
t2 = t1 + h = 0.02
x2 = x1 + f(t1,x1,v1)h = 0.0639
v2 = v1 + g(t1,x1,v1)h = 12.75
...
...
xn = xn-1 + f(tn-1,xn-1,vn-1)h
demo
vn = vn-1 + g(tn-1,xn-1,vn-1Matlab
)h
...
tn = tn-1 + h
Engineering Computation
28
1. Repeat analysis at each time step with step length h and h/2.
Compare results to estimate local error. (C&C 25.5.1) Use
Richardson extrapolation to obtain higher order result.
2. Use a matched pair of Runge-Kutta formulas of order r and
r+1 which use common values of ki, and yield estimate or
bound local truncation error.
C&C 25.5.2 discuss 4th-5th-order Runge-Kutta-Fehlberg pair.
Engineering Computation
29
30
dy
= 1000 y + 3000 2000e t
dt
With initial conditions y(0) = 0 and with solution
Slow term
31
In the solution
y (t ) 3 2e t
We would need a very small time step h = t to capture the
behavior of the rapid transient and to preserve a stable and accurate
solution, and this would then make it very laborious to compute the
slowly evolving solution.
Matlab demo
Engineering Computation
32
dy
= ay
dt
with solution
y (t ) = y0 e
at
dyi
yi +1 = yi +
h = yi ayi h = yi (1 ah)
dt
yn = y0 (1 ah)n
Engineering Computation
33
dyi +1
yi
yi +1 = yi +
h = yi ayi +1h yi +1 =
1 + ah
dt
34
Engineering Computation
35
(h3)-Corrector
j
i +1
m
j1
f
(x
,
y
)
+
f
(x
,
y
m
i i
i +1 i +1 )
= yi +
h
2
36
Multi-step methods
Two general schemes solving ODE's:
1. Newton-Cotes Formulas
n 1
n +1
y
h
c
f
O(h
) open predictor
+
+
k ik
in
k =0
yi+1 =
n 1
y
n +1
h
c
f
O(h
) closed corrector
+
+
k ik +1
in +1
k =0
37
Engineering Computation
38
1 m
E c = yi +1 y i0+1
5
m
0
y
y
yim+1 yim+1 i+1 i+1
5
m
yim = unmodified yi+1
from previous step
Engineering Computation
39
y i+1
40
Correctors:
refine value of yi+1 given a y i+1
more stable numerically no spurious solutions which go out
of control
Adams-Moulton 2nd-Order closed (Non-self starting Heun):
yi+1 = yi + h/2{(xi+1, y i+1 ) +(xi, yi)} + O(h3)
Engineering Computation
41
Predictor-Corrector solution
Example: Undamped, harmonically driven oscillator
d2x
dt
+ kx = P(t)
m = mass
k = spring constant
P(t) = forcing function = P sin( t)
= driving frequency
Initial conditions:
x(0) = 0 and
Analytical solution:
x(t) =
Engineering Computation
P
2
m( )
sin(t) +
k
=
= circular frequency
m
2
T=
= natural period
dx
(0) = 0
dt
P
2
m( )
sin( t)
42
d2x
dt
+ kx = P(t)
with v(0) = 0
g = 80 sin(8t) - 162x
Use 4th-ord. Adams Method to solve from t=0 until t=1 w/ h=0.1
Engineering Computation
43
d2x
dt
+ kx = P(t)
Engineering Computation
x(t)
y(t)
0.0
0.0000
0.0000
0.1
0.1038
2.6234
0.2
0.5324
5.1401
0.3
0.8692
0.4949
44
h
{55f (x i , yi ) 59 f (x i 1 , yi 1 ) + 37 f (x i 2 , yi 2 ) 9 f (x i 3 , yi 3 )} + O(h 5 )
24
Example :
45
h
{9 f (x i +1 , yi +1 ) + 19 f (x i , yi ) 5f (x i 1 , yi 1 ) + f (x i 2 , yi 2 )} + O(h 5 )
24
= -6.7435
46
47
Summary
Single-step
Euler
Heun
Mid-point
RK4
Multi-step (predictor-corrector)
Non-self-starting Heun
Milne (Newton-Cotes n=3)
Adams (Adams-Bashford, Adams-Moulton)
Stiffness - stability
Adaptive methods local error estimates modifiers
Half step
RK Fehlberg
Engineering Computation
48
49
Engineering Computation
50
Beam Equation
Sailboat mast deflection problem
d4v
dz
f (z)
EI
where:
Engineering Computation
E =
I =
f(z) =
v(x) =
z =
E I v'' =
E I v''' =
v''(L) = 0; v'''(L) = 0
(C&C 27.1)
d 2T
= h (T Ta )
2
dx
TL
TR
Ta
Engineering Computation
52
Engineering Computation
53
(1)
zo
yf
(2)
(2)
zo
yf
(1)
(1)
yf yf (1)
[This equation
is not in C&C
in general form]
54
d2x
dt 2
+ kx = P(t)
or
d2x
dt 2
+ 2 x =
P(t)
m
k
=
= circular frequency
m
k = spring constant
2
P(t) = forcing function = P sin( t) T =
= natural period
Now, we are given boundary conditions:
m = mass
55
d2x
dt 2
+ 2 x =
P(t)
m
with x(0) = 0
dv P sin( t)
=
2 x = g(t, x, v)
dt
m
with v(0) = v0
56
Engineering Computation
OK
57
xo
x = h
Engineering Computation
...
i-1
i+1
...
n+1
xf
58
Approach:
1. Divide domain to obtain n interior discrete points
(usually evenly spaced @ h).
2. Write a finite difference expression for the ODE at each
interior point.
3. Use known values of y at x = xo and x = xf
4. Set up n linear equations with n unknowns. System is banded
and often symmetric, so solve with an efficient method.
Engineering Computation
59
f (z)
EI
Engineering Computation
E =
I =
f(z) =
v(x) =
z =
E I v'' =
E I v''' =
v''(L) = 0; v'''(L) = 0
d4 v
f (z)
= v =
Sailboat mast deflection problem:
4
EI
dz
at the base (z = 0): v(0) = 0; v'(0) = 0;
at the top (z = L):
v '''' =
v ''' =
v '' =
d4v
dx
d3v
dx 3
d2v
dx 2
v''(L) = 0; v'''(L) = 0
vi 2 + 2vi 1 2vi +1 + vi + 2
vi 1 2vi + vi+1
h
2h 3
h2
dv vi1 vi+1
v' =
dx
2h
Engineering Computation
[dist. load,f(z)]/EI
(shear)/EI
(bending moment)/EI
(slope)
61
f (z)
=
4
EI
dz
v''(L) = 0; v'''(L) = 0
Use equation:
Use v'(0) to
get in terms
of v(1)
d4v
v(0)
given
Engineering Computation
d 4v
dz 4
9 10
Imaginary Nodes
f (z)
EI
Use v''(L) = 0
to get in terms
of v(9) & (10)
Use v'''(L) = 0
to get in terms
of other v's
62
@ pt. i:
d4v
f (z)
=
4
EI
dz
vi-2 4 vi-1 + 6 vi 4 vi+1 + vi+2 = h4 f(xi)/EI
v-1 4 v0 + 6 v1 4 v2 + v3 = h4 f(x1)/EI
(1)
@i=2
v0 4 v1 + 6 v2 4 v3 + v4 = h4 f(x2)/EI
(2)
@i=9
(3)
@ i = 10
(4)
63
d4v
dz 4
f (z)
EI
v(0) = 0:
v0 = 0
v'(0) = 0:
v 1 v1
=0
2h
v''(L) = 0:
v9 2v10 + v11
v'''(L) = 0:
Engineering Computation
h2
2h 3
v-1 = v1
v11 = 2v10 + v9
=0
=0
d4v
dz 4
f (z)
EI
v0 = 0
v11 = 2v10 + v9
v-1 = v1
v12 = v8 - 4v9 + 4v10
@i=1
7 v1 4 v2 + v3 = h4f(x1) / EI
(1a)
@i=2
4 v1 + 6 v2 4 v3 + v4 = h4 f(x2)/ EI
(2a)
@i=9
v7 4 v8 + 5 v9 2 v10 = h4f(x9) / EI
(3a)
@ i = 10
(4a)
Engineering Computation
65
7 -4 1
v1
4 6 -4 1
v
2
1 4 6 4 1
v3
v
1
-4
6
-4
1
v5 h 4f
1 -4 6 -4 1
=
1 -4 6 -4 1
v6 EI
v7
1 -4 6 -4 1
1 -4 6 -4 1 v8
1 -4 5 -2 v9
1 -4 2 v10
Engineering Computation
f (x1 )
f (x )
2
f (x 3 )
f (x 4 )
f (x 5 )
f
(x
)
6
f (x 7 )
f (x8 )
f (x 9 )
f (x10 )
66
Once we have solved for all the vi, we can obtain secondary
results such as bending moments and shear forces by substituting
the finite-divided-difference operators and the values of the vi
into such equations as:
M = EI v''
V = EI v'''
For more refined results, we can use a smaller h and more
segments.
Engineering Computation
67
Shooting method
Conceptually simple and easy.
Inefficient for higher-order systems w/ many boundary
conditions.
May not converge for nonlinear problems.
Can blow up for bad guess of initial conditions.
Finite Difference method
Stable
Direct (not iterative) for linear problems.
Requires solution of simultaneous algebraic eqns.
More complex.
FD better suited for eigenvalue problems.
Engineering Computation
68
3k
M
x2
2k
M
x3
k
M
The displacement of each spring is measured relative to its own local coordinate
system with an origin at the spring's equilibrium position.
d 2 x1
m 2 = 3kx1 2k(x1 x 2 )
dt
d2x2
m 2 = 2k(x 2 x1 ) k(x 2 x 3 )
dt
d2 x3
m 2 = k(x 3 x 2 )
Engineering Computation
dt
69
d2x/dt2 = - 2 ai cos t
a1 = 5a1 + 2a 2
k
m2
a 2 = 2a1 3a 2 + a 3
k
m2
a3 = a 2 a3
Engineering Computation
==>
5a1 2a 2 = a1
==> 2a1 + 3a 2 a 3 = a 2
==>
a 2 + a 3 = a 3
70
5a1 2a 2 = a1
2a1 + 32a 2 a 3 = a 2
a1 + a 2 = a 3
or
5 2 0 a1
a1
==> 2 3 1 a 2 = a 2
0 1 1 a
a 3
3
[A]
{x} = {x}
0 a1
5 2
2 3 1 a 2 = 0
0
a
1
1
[A I ]
Engineering Computation
{x} = 0
71
0
5 2
det 2 3 1 = 0
0
1
1
2 = 2.29
3 = 0.42
Slow oscillation
72
1 a 2i = 0
0
a
1
1
i 3i
2
0 a1i
5 6.29
2
3 6.29
1 a 2i = 0
0
a
1
1
6.29
3i
a2
= 0.645
a1
Engineering Computation
a3
= 0.122
a1
73
a2
= 0.645
a1
a3
= 0.122
a1
Only the relative values of the ai's are significant. Thus setting
a1 = 1.00 we have:
Slow
Fast
for = 6.29
1.000
{a}1 = 0.645
0.122
Engineering Computation
for 2 = 2.29
{a}2
0.74
= 1.000
0.77
for 2 = 0.42
{a}2
0.25
= 0.55
1.000
74
if j i
if j = i
75
b {x }
i
i =1
[A] {y} =
b [A]{x } = b {x }
i
i =1
i =1
i
i
bi {x i } where
<1
1
1
i=2
Engineering Computation
76
i
2
2
[A] {y} = 1 b1 {x1} +
bi { x i }
1
i
2
=
i =2
i
Since ==> 0 for all i 1 as m ==> ,
1
then [A]m {y} 1m b1{x1}
Since we can only know the relative values of the elements of {x},
we may normalize {x}. If {x} is normalized such that the largest
element is equal to {1}, then is the first eigenvalue, 1
Engineering Computation
77
3 7 9 x1
x1
9 4 3 x = x
2
2
x
9 3 8 x 3
3
Find the maximum eigenvector. Initial guess: {y}T = {1 1 1}
3 7 9 1 19
[A]{y} = 9 4 3 1 = 16 ==> 20
9 3 8 1 20
Approx.
eigenvalue
Engineering Computation
0.95
0.80
1.00
eigenvector
78
3 7
[A]2 {y} = 9 4
9 3
Approximate error, a:
(ei, j ei1, j
max
*100% =
ei, j
j
2nd iteration
9 0.95
0.92084
1.00
8 1.00
0.92084 0.95
*100% = 4.2%
0.92084
3 7 9 0.92084
0.92420
3rd iteration
1.00
9 3 8 1.00
0.92084 0.95
a =
*100% = 0.75%
0.92084
Engineering Computation
79
After 10 iterations:
= 18.622
Engineering Computation
0.92251
{x} = 0.77301
1.00
a = 0.00033%
80
81
Engineering Computation
82
83
Compute xt+1 = A xt / || xt ||
for larger and larger t to estimate largest (A).
Always works for Symmetric A.
Engineering Computation
84
Compute xt+1 = B xt / || xt ||
for larger and larger t to estimate largest (B).
Here B = A-1. Eigenvalues of B are inverse of those of A.
BUT WE DO NOT COMPUTE A-1 ! (Dont do it.)
Instead use LU decomposition of A.
Engineering Computation
85
86