lecture 34 - ordinary differential equations - bvp cven 302 november 28, 2001
Post on 21-Dec-2015
215 views
TRANSCRIPT
Lecture 34 - Ordinary Differential Lecture 34 - Ordinary Differential Equations - BVP Equations - BVP
CVEN 302
November 28, 2001
Systems of Ordinary Differential Systems of Ordinary Differential Equations - BVPEquations - BVP
• Shooting Method for Nonlinear BVP
• Finite Difference Method
• Partial Differential Equations
Shooting Method for Nonlinear Shooting Method for Nonlinear ODE-BVPsODE-BVPs
• Nonlinear
ODE
• Consider with guessed slope t
• Use the difference between u(b) and yb to adjust u’(a)
• m(t) = u(b, t) - yb is a function of the guessed value t
• Use secant method or Newton method to find the correct t value with m(t) = 0
ba y)b(y ,y)a(ybxa , )y,y,x(fy
t)a(u ,yu(a) )u,u,x(fu
a
Nonlinear Shooting Based on Secant Nonlinear Shooting Based on Secant MethodMethod
• Nonlinear
ODE
0))b(y),b(yh( ,y)a(ybxa , )y,y,x(fy
a
tol1)-t(i-t(i) until iterate :4 Step
1)m(i2)m(i1)m(i
2)t(i1)t(i1)t(it(i)
estimate new a obtain to methodsecant use :3 Step
m(2)Error t(2)(a)u ,yu(a) use:2 Step
m(1)Error t(1)(a)u ,yu(a) use:1 Step
a
a
MATLAB Example in Nonlinear Shooting MATLAB Example in Nonlinear Shooting MethodMethod
• Nonlinear shooting with secant method
• Convert to two first-order ODE-IVPs
• Update t using the secant method
)1x/(1y solution exact
025.0)1(y)1y())1(y),1(y( , h1)0y(
1x0 , yy2y
t)0(z ,zz2z
1)0(z , zz
yz ,yz let
2212
121
21
Nonlinear Shooting - Secant MethodNonlinear Shooting - Secant Method
y(x)
y’(x)
Nonlinear ShootingNonlinear Shooting Based on Newton’s Method Based on Newton’s Method
• Nonlinear
ODE
Check for convergence of m(t)
ba y)b(y ,y)a(y
bxa , )y,y,x(fy
1(a)v 0,v(a)
t(a)u ,yu(a)
)uu,(x,fv )uu,(x,fvv
)uu,f(x,u ka
uu
)t,b(v
mtt ,Otherwise
stop ,tolm if
y)tu(b,)tm(
kk1k
bkk
Nonlinear ShootingNonlinear Shooting Based on Newton’s Method Based on Newton’s Method
• Nonlinear
ODE-IVP
• Chain Rule
b
a
y)t,b(u)t(m
t)a(u ,y)a(u , )u,u,x(fu
t
u
u
f
t
u
u
f
t
x
x
f
t
)u,u,x(f
t
u
1t/u(a)v' t)t,a(u
vfvfvt
u
u
f
t
u
u
f
t
ut
uv ,
t
uv then ,
t
uv let
uu
x and t are independent
0
Nonlinear Shooting with Newton’s MethodNonlinear Shooting with Newton’s Method
• Solve ODE-IVP
• Construct the auxiliary equations
1)0(u, 1)0u(
, u
)u(u
2)1(, y1)0y(
, y
)y(y
22
1)0(v ,0)0(v
vu
u2v
u
)u(v
u
u2
u
f)u,u,x(f
u
)u(
u
f)u,u,x(f
2
2
u
2
2
u
Nonlinear Shooting with Newton’s MethodNonlinear Shooting with Newton’s Method
• Calculate m(t) -- deviation from the exact BC
• Update t by Newton’s method
),()(
),()(
tbutm
ytbutm
tt
b
),( ;)(
)(tbu
t
m(t)m v
tm
tmtt tt
1it
1i1ii
Finite-Difference MethodsFinite-Difference Methods
• Divide the interval of interest into subintervals
• Replace the derivatives by appropriate finite-difference approximations in Chapter 11
• Solve the system of algebraic equations by methods in Chapters 3 and 4
• For nonlinear ODEs, methods in Chapter 5 may be used
i1in0 xxh
abh ,bx ,ax
Finite-Difference MethodFinite-Difference Method
• General Two-Point BVPs
• Replace the derivatives by appropriate finite-difference approximations
y(b) ,y(a)
bxa ),x(ry)x(qy)x(py
h2
yy)x(y ,
h
yy2y)x(y 1i1i
i21ii1i
i
xixi-1 xi+1
hh h h
Finite-Difference MethodFinite-Difference Method
• Central difference approximations
• Tridiagonal system
i2
1iiii2
1ii
iii1i1i
i21ii1i
rhy p2
h1y qh2y p
2
h1
ryqh2
yyp
h
yy2y
21ii1i
i
1i1ii
h
yy2y)x(y
h2
yy)x(y
Finite-Difference MethodFinite-Difference Method
• Central Difference ==> Tridiagonal system
)/2ph1(rh
rh
rh
)/2ph1(rh
y)/2ph1(rh
rh
rh
y)/2ph1(rh
y
y
y
y
)qh2(000
0)qh2(p(h/2)10
0p(h/2)1)qh2(p(h/2)1
000)qh2(
1-n1n2
32
22
112
n1-n1n2
32
22
0112
1n
3
2
1
1n2
32
3
222
2
12
Finite-Difference Method for Finite-Difference Method for Nonlinear BVPsNonlinear BVPs
• Nonlinear ODE-BVPs
• Evaluate fi by appropriate finite-difference approximations
y(b) ,y(a)
bxa , )y,y,x(fy
0fh
yy2yi2
1ii1i
xixi-1 xi+1
hh h h
Finite-Difference Method for Finite-Difference Method for Nonlinear BVPsNonlinear BVPs
• SOR method
• Iterative solution• Convergence criterion
)fhyy 2y()1(2
1y i
21ii1ii
P)y,y,x(f
Q)'y,y,x(fQ0 with
P/2h
2/Qh
y
y2
Example 14.12 - MATLABExample 14.12 - MATLAB
• Note error in Text
i
2
21i1i
i
21i1i
i
i2
1ii1ii
yh4
)yy(
y
h2/)yy( f
)fhyy 2y()1(2
1y
2 y(1) , 1 y(0) ,y
)y()y,y,x(fy
2
fi : negative sign
Chapter 15
Partial Differential Equations
Classification of PDEsClassification of PDEs• General form of linear second-order PDEs with
two independent variables
• linear PDEs: a, b, c,….,g = f(x,y) only
0gfueuducubuau yxyyxyxx
roots)complex (2 Elliptic ,0ac4b
root)double (1 Parabolic ,0ac4b
roots) real (2 Hyperbolic ,0ac4b
2
2
2
Heat Equation: Parabolic PDEHeat Equation: Parabolic PDE
• Heat transfer in a one-dimensional rod
Tt0 , )t(g)t,a(u
)t(gt)u(0,
ax0 f(x),u(x,0)
Tt0 a,x0 ;x
uc
t
u
2
1
2
2
x = 0 x = ag1(t) g2(t)
0
1
2
3
4
5
6
7
8
9
10
0 1 2 3 4 5 6 7 8 9 10
Discretize the solution domain in space and time with h = x and k = t
Time(j index)
space (i index)
x
t
Initial and Boundary ConditionsInitial and Boundary Conditions
0
1
2
3
4
5
6
7
8
9
10
0 1 2 3 4 5 6 7 8 9 10
Initial conditions : u(x,0) = f(x)
u(0, t) = g1(t)
u(a, t) = g2(t)
Explicit Euler method
Heat EquationHeat Equation• Finite-difference
(i,j) (i+1,j)(i-1,j)
(i,j+1)u(x,t)
xx
t
t
xi xi+1xi-1
tj
tj+1
)uu2u(h
ccu
)uu(k
1u
j,1ij,ij,1i2xx
j,i1j,it
Forward-difference
Central-difference
at time level j
Explicit MethodExplicit Method
• Explicit Euler method for heat equation
• Rearrange
jkt ,m/Tt kihx ,n/ax h
letj
i
)uu2u(h
c)uu(
k
1cuu j,1ij,ij,1i2j,i1j,ixxt
j,1ij,ij,1i
j,1ij,ij,1i2j,i1j,i
ruu)r21(ru
)uu2u(h
ckuu
22 x
t c
h
ckr
5.0r0 Stability:
Explicit Euler MethodExplicit Euler Method
• Stable
• Unstable (negative coefficients)
j,1ij,ij,1i1j,i ruu)r21(ruu
j,1ij,1i1j,i
j,1ij,ij,1i1j,i
j,1ij,ij,1i1j,i
j,1ij,ij,1i1j,i
u 5.0u 5.0u 5.0r
u 4.0u 2.0u 4.0u 4.0r
u 1.0u 8.0u 1.0u 1.0r
u 01.0u 98.0u 01.0u 01.0r
j,1ij,ij,1i1j,i
j,1ij,ij,1i1j,i
j,1ij,ij,1i1j,i
u100u 199u100u 100ru 10u 19u 10u 10r
u u u u 1r
Heat Equation: Explicit Euler MethodHeat Equation: Explicit Euler Method
r = 0.5
Example: Explicit Euler MethodExample: Explicit Euler Method • Heat Equation (Parabolic PDE)
• c = 0.5, h = 0.25, k = 0.05
e60)t,1(u ,e20t)u(0,
x4002u(x,0)
1x0 ;cuu
t2t
xxt
1 2 3 4020 + 40 x
60e -2t20e -t
0
1
2
ExampleExample • Explicit Euler method
• First step: t = 0.05
j,1ij,ij,1i
j,1ij,ij,1i1j,i
22
u4.0u2.0u4.0
ruu)r21(ruu
4.0)25.0(
)05.0)(5.0(
h
ckr
29024508.54e60u
50)60(4.0)50(2.0)40(4.0u4.0u2.0u4.0u
40)50(4.0)40(2.0)30(4.0u4.0u2.0u4.0u
30)40(4.0)30(2.0)20(4.0u4.0u2.0u4.0u
02458849.19e20u
10.01,4
0,40,30,21,3
0,30,20,11,2
0,20,10,01,1
05.01,0
• Second step: t = 0.10
1 2 3 4020 + 40 x
60e -2t20e -t
12384518.49e60u
71609803.47)2924508.54(4.0)50(2.0)40(4.0
u4.0u2.0u4.0u
40)50(4.0)40(2.0)30(4.0u4.0u2.0u4.0u
6098354.29)40(4.0)30(2.0)02458849.19(4.0
u4.0u2.0u4.0u
09674836.18e20u
20.02,4
1,41,31,22,3
1,31,21,12,2
1,21,11,02,1
10.02,0
30 40 50
29.61 40 47.72
Heat Equation: Time-dependent BCsHeat Equation: Time-dependent BCs
r = 0.4
• Stability for Explicit Euler Method
• It can be shown by Von Neumann analysis that
• Switch to Implicit method to avoid instabilityc
x
2
1t or
2
1r
2
Numerical StabilityNumerical Stability
Explicit Euler Method: StabilityExplicit Euler Method: Stability
Unstable !!
r = 1
Implicit Euler methodImplicit Euler method
0
1
2
3
4
5
6
7
8
9
10
0 1 2 3 4 5 6 7 8 9 10
Initial conditions : u(x,0) = f(x)
u(0, t) = g1(t)
u(a, t) = g2(t)
Unconditionally Stable
Implicit MethodImplicit Method• Finite-difference
(i,j)
(i+1,j+1)(i-1,j+1) (i,j+1)
T(x,t)
xx
t
t
xi xi+1xi-1
tj
tj+1
)uu2u(h
ccu
)uu(k
1u
1j,1i1j,i1j,1i2xx
j,i1j,it
Forward-difference
Central-difference at time level j+1
Implicit Euler MethodImplicit Euler Method • Implicit Euler method for heat equation
• Tridiagonal matrix (Thomas algorithm)
• Unconditionally stable
j,i1j,1i1j,i1j,1i
1j,1i1j,i1j,1i2j,i1j,i
uruu)r21(ru
)uu2u(h
c)uu(
k
1
1j,nj,1n
j,3
j,2
1j,0j,1
1j,1n
1j,3
1j,2
1j,1
ruu
u
u
ruu
u
u
u
u
r21r
r
rr21r
rr21r
rr21
Implicit Euler MethodImplicit Euler Method
Unconditionally stable
r = 2
Example: Implicit Euler MethodExample: Implicit Euler Method • Heat Equation (Parabolic PDE)
• c = 0.5, h = 0.25, k = 0.1
e60)t,1(u ,e20t)u(0,
x4002u(x,0)
1x0 ;cuu
t2t
xxt
1 2 3 4020 + 40 x
60e -2t20e -t
0
1
ExampleExample • Implicit Euler method
j,i1j,1i1j,i1j,1i
j,i1j,1i1j,i1j,1i
22
uu)8.0(u)6.2(u)8.0(
uu)r(u)r21(u)r(
8.0)25.0(
)10.0)(5.0(
h
ckr
1403
02
1001
13
12
11
ruu
u
ruu
u
u
u
r21r0
rr21r
0rr21
,,
,
,,
,
,
,
• Solve the tridiagonal matrix
1 2 3 4020 + 40 x
60e -2t20e -t
0
1
19426454.46
50751457.38
95515793.28
u
u
u
)e60(8.050
40
)e20(8.030
u
u
u
6.28.00
8.06.28.0
08.06.2
1,3
1,2
1,1
2.0
1.0
1,3
1,2
1,1
28.96 38.51 46.19
Crank-Nicolson methodCrank-Nicolson method
0
1
2
3
4
5
6
7
8
9
10
0 1 2 3 4 5 6 7 8 9 10
Initial conditions : u(x,0) = f(x)
u(0, t) = g1(t)
u(a, t) = g2(t)
Implicit Euler method : first-order in timeCrank-Nicolson : second-order in time
Crank-Nicolson MethodCrank-Nicolson Method • Crank-Nicolson method for heat equation• Average between two time levels
• Tridiagonal matrix
• Unconditionally stable (neutrally stable)• Oscillation may occur
)uu2u(h2
c
)uu2u(h2
c)uu(
k
1
1j,1i1j,i1j,1i2
j,1ij,ij,1i2j,i1j,i
j,1ij,ij,1i1j,1i1j,i1j,1i u2
ru)r1(u
2
ru
2
ru)r1(u
2
r
General Two-Level MethodGeneral Two-Level Method • General two-stage method for heat equation
• Weighted-average of spatial derivatives between two time levels n and n+1
)uu2u(h
)1(c
)uu2u(h
c)uu(
k
1
1j,1i1j,i1j,1i2
j,1ij,ij,1i2j,i1j,i
scheme Nicolson-Crank :1/2λscheme Euler explicit :1λscheme Euler implicit :0λ
Example: Crank-Nicolson MethodExample: Crank-Nicolson Method • Heat Equation (Parabolic PDE)
• c = 0.5, h = 0.25, k = 0.1
e60)t,1(u ,e20t)u(0,
x4002u(x,0)
1x0 ;cuu
t2t
xxt
1 2 3 4020 + 40 x
60e -2t20e -t
0
1
ExampleExample • Crank-Nicolson method
• Tridiagonal matrix (r = 0.8)
j1,iji,j1,i1j1,i1ji,1j1,i
j1,iji,j1,i1j1,i1ji,1j1,i
22
0.4u0.2u0.4u0.4u1.8u0.4u
u2
rr)u(1u
2
ru
2
rr)u(1u
2
r
8.0)25.0(
)10.0)(5.0(
h
ckr
1,40,40,30,2
0,30,20,1
1,00,20,10,0
1,3
1,2
1,1
u2
ru
2
ru)r1(u
2
r
u2
ru)r1(u
2
r
u2
ru
2
ru)r1(u
2
r
u
u
u
r12
r0
2
rr1
2
r
02
rr1
• Solve the tridiagonal matrix
1 2 3 4020 + 40 x
60e -2t20e -t
0
1
42746748.47
29975855.39
42144598.29
u
u
u
64953807.69
40
23869934.37
)e60(4.0)60(4.0)50(2.0)40(4.0
)50(4.0)40(2.0)30(4.0
)e20(4.0)40(4.0)30(2.0)20(4.0
u
u
u
8.14.00
4.08.14.0
04.08.1
1,3
1,2
1,1
2.0
1.0
1,3
1,2
1,1
29.42 39.30 47.43
Implicit Euler methodImplicit Euler method
Unconditionally stable
r = 2
Heat Equation with Insulated Heat Equation with Insulated BoundaryBoundary
• No heat flux at x = 0 and x = a
Tt0 , 0)t,a(u
0t)(0,u
ax0 f(x),u(x,0)
Tt0 a,x0 ;x
uc
t
u
x
x
2
2
x = 0 x = a
ux(a,t) = 0ux(0,t) = 0
Insulated BoundaryInsulated Boundary• No heat flux at x = a
1n1n1n1n
j,1nj,1nx uu 0
xx
uu)t,a(u
j,nj,1n
j,1nj,nj,1n1j,n
u)r21(ru2
ruu)r21(ruu
x = a
xn+1xn-1 xn
ux(a,t)=0