MAFE208IU-L15 - Parabolic and Hyperbolic Equations
MAFE208IU-L15 - Parabolic and Hyperbolic Equations
MAFE208IU-L15 - Parabolic and Hyperbolic Equations
t
boundary boundary
value value
u(0, t ) = g1 (t ) u(l , t ) = g2 (t )
initial value
O x
MAFE208IU-L15
u( x,0) = u0 ( x) l 3
Finite Difference Grid
T = maximum time used to compute the solution; = [0, l ] [0, T ]
is divided into m equal parts along x − axis and n parts along t − axis
tn T • • •
• • •
• • • boundary points
• • • • interior points
t2 • • •
t1 • • • l T
Step sizes: x = , t =
O x1 x2 l xm m n
u ( xi , tk +1 ) − u ( xi , tk ) u ( xi +1 , tk ) − 2u ( xi , tk ) + u ( xi −1 , tk )
= + f ( xi , tk )
t (x) 2
Let fi = f ( xi , tk ), u u ( xi , tk ), 0 i m, 1 k n
k k
i
k +1
u −u k
u − 2u + u k k k
i
=i i +1 i i −1
+ fi k
t (x)2
Explicit method:
uk +1
i = u + (u − 2u + u ) + t fi
k
i
k
i +1
k
i
k
i −1
k
t
where = , 1 i m − 1, k = 0,1, 2,..., n − 1
MAFE208IU-L15
(x) 2
5
Matrix Form of Explicit Method
tn T • • •
• • •
• • •
tk +1 • • • uik +1 = uik + (uik+1 − 2uik + uik−1 ) + t f i k
tk • • •
t1 • • •
k +1
V = AV + Bk k
O xi −1 xi xi +1 L xm
u1k 1 − 2 0 0 f1k g1k
k k
u
2 1 − 2 0 f
2 0
V k = u3k , A = 0 1 − 2 0 , Bk = t +
0
u k 0 1 − 2 f k g k
m −1 0 0 m −1 2
Example 1
Use the explicit method to solve for the temperature
distribution of a long, thin rod with a length of 10 cm
and the following values
= 0.8 cm /s, 2
x = 2 cm, t = 0.1 s
u ( x, 0) = u0 ( x) = 0 C, 0 x 10
o
100 50
x
MAFE208IU-L15 7
Solution Heat equation u 2u
= 2 , = 0.8
t x
t 0.8(0.1)
= = =0.02
uk +1
= u + (u
k k
− 2u + u )
k k (x)2 2 2
i i i +1 i i −1
at the time t=0.1 and t=0.2 using explicit method with ∆x=0.2, ∆t=0.1
and find error. Exact solution:
− 2 t
u ( x, t ) = e 4
sin(2 x)
MAFE208IU-L15 9
Implicit Methods
Consider CDA of 1st derivative at middle grid point with
time step ∆t/2:
u u ( xi , tk +1 ) − u ( xi , tk ) uik +1 − uik
( xi , tk +1/2 )
t t t
2u u ( xi +1 , tk ) − 2u ( xi , tk ) + u ( xi −1 , tk )
( xi , tk +1/2 ) (1 − )
x 2
(x) 2
u ( xi +1 , tk +1 ) − 2u ( xi , tk +1 ) + u ( xi −1 , tk +1 )
+
(x) 2
MAFE208IU-L15 10
Implicit Methods
tn T • • •
• • •
• • •
tk +1 • • •
tk +1/2 • • •
tk • • •
O xi −1 xi xi +1 L xm
MAFE208IU-L15 11
A set of implicit methods: Variable-weighted
implicit formula
u 2u t
( xi , tk +1/2 ) = 2 ( xi , tk +1/2 ) =
t x (x) 2
(1 − )
t
where = 1 i m − 1, k = 0,1, 2,..., n − 1
(x) 2
−u k +1
i −1 + (1 + 2 )u
k +1
i − u
k +1
i +1 =u
k
i
MAFE208IU-L15 13
Crank-Nicholson Method
Taking θ=1/2 defines Crank-Nicholson implicit method:
− u k +1
i −1 + 2(1 + )u k +1
i − u
k +1
i +1 = u + 2(1 − )u + u
k
i −1
k
i
k
i +1
t
where = , 1 i m − 1, k = 0,1, 2,..., n − 1
(x) 2
Accuracy: O(x 2 + t 2 )
Using boundary conditions, first and last equations in C-N method are
2(1 + )u k +1
1 − u k +1
2 = (g + g
k
1
k +1
1 ) + 2(1 − )u + u
k
1
k
2
−umk +−12 + 2(1 + )umk +−11 = umk −2 + 2(1 − )umk −1 + ( g2k + g2k +1 )
MAFE208IU-L15 14
Crank-Nicholson Method
Solve k +1
AV k
= BV + Ck
2(1 + ) − 0 0 u1k
− k
2(1 + ) − 0 u2
A= 0 − 2(1 + ) 0 , V k = u3k
−
0 − 2(1 + ) u k
0 0 m −1
2(1 − ) 0 0 ( g1k + g1k +1 )
2(1 − ) 0 0
B= 0 2(1 − ) 0 , and Ck =
0
0 2(1 − ) ( g k + g 2k +1 )
0 0 2
MAFE208IU-L15 15
Example 2
Use the Crank-Nicholson method to solve for the
temperature distribution of a long, thin rod with a
length of 10 cm at time 2 s and the following values
= 1 cm /s, 2
x = 2 cm, t = 1 s
u ( x, 0) = u0 ( x) = 0 C, 0 x 10
o
100 50
x
MAFE208IU-L15 16
Solution: 2(1 + )u1k +1 − u2k +1 = 200 + 2(1 − )u1k + u2k
−uik−+11 + 2(1 + )uik +1 − uik++11 = uik−1 + 2(1 − )uik + uik+1 , i = 2,3
System
−umk +−12 + 2(1 + )umk +−11 = umk −2 + 2(1 − )umk −1 + 100 ,
t 1
= = can be expressed as a Tridiagonal system of equations:
(x)2 4
AV k +1 = BV k + Ck
2(1 + ) − 0 0 10 / 4 −1/ 4 0 0
where − 2(1 + ) − 0 −1/ 4 10 / 4 −1/ 4 0
A= =
0 − 2(1 + ) − 0 −1/ 4 10 / 4 −1/ 4
0 0 − 2(1 + ) 0 0 −1/ 4 10 / 4
2(1 − ) 0 0 6 / 4 1/ 4 0 0
2(1 − ) 0 1/ 4 6 / 4 1/ 4 0
B= =
0 2(1 − ) 0 1/ 4 6 / 4 1/ 4
0 0 2(1 − ) 0 0 1/ 4 6 / 4
u1k ( g1k + g1k +1 ) 200 50
k 0
u 0 0
V = k , and Ck =
k 2 = =
u3 0 0 0
k
MAFE208IU-L15
4
u
( g k
2 + g 2k +1 ) 100 25 17
10 / 4 −1/ 4 0 0 10 / 4 −1/ 4 0 0
−1/ 4 10 / 4 −1/ 4 0 0 99 / 40 −1/ 4 0
⎯⎯⎯⎯⎯
R 2 − ( −1/10) R1
→
0 −1/ 4 10 / 4 0 0 −1/ 4 10 / 4 0
0 0 −1/ 4 10 / 4 0 0 −1/ 4 10 / 4
10 / 4 −1/ 4 0 0
0 99 / 40 −1/ 4 0
⎯⎯⎯⎯⎯→
R 3− ( −10/99) R 2
0 0 245 / 99 0
0 0 −1/ 4 10 / 4
10 / 4 −1/ 4 0 0
0 99 / 40 −1/ 4 0
R 4 − ( −99/980) R 3
⎯⎯⎯⎯⎯⎯ → =U
0 0 245 / 99 0
0 0 0 10 / 4
LU Decomposition of A:
1 0 0 0
−1/10 1 0 0
A = LU , L =
0 −10 / 99 1 0
MAFE208IU-L15 0 0 −99 / 980 1 18
1 0 0 0 10 / 4 −1/ 4 0 0
−1/10 1 0 0 0 99 / 40 −1/ 4 0
A = LU , L = ,U =
0 −10 / 99 1 0 0 0 245 / 99 0
0 0 −99 / 980 1 0 0 0 10 / 4
Ck = C = const
MAFE208IU-L15 20
Finite difference method for Hyperbolic Partial
Differential Equations
Approximate solution of the wave equation
2u ( x, t ) 2
u ( x, t )
=c 2
0 x l, t 0
t 2
x 2
with boundary conditions u(0, t ) = u(l , t ) = 0, t 0
and initial conditions u ( x, 0) = f ( x),
u ( x, 0)
= g ( x), 0 xl
t
Choose step size in space ∆x>0, in time ∆t>0. CDA of 2nd derivatives:
2u ( xi , tk ) 1 1 k −1 k +1
(u ( x , t − t ) − 2u ( x , t ) + u ( x , t + t )) = ( u − 2u k
+ u )
t t t
2 2 i k i k i k 2 i i i
2u ( xi , tk ) 1 1
( u ( x − x , t ) − 2u ( x , t ) + u ( x + h, t )) = (u k
i −1 − 2u k
+ u k
i +1 )
x x x
2 2 i k i k i k 2 i
MAFE208IU-L15 21
Finite difference method for wave equation
c 2
t 2
uik +1 = 2uik − uik −1 + (u k
i −1 − 2u k
+ u k
i +1 )
x 2 i
∆t
u ( x,0) = f ( x)
t ut ( x,0) = g ( x)
x ∆x
MAFE208IU-L15 22
Finite difference method for wave equation
Use initial derivative to make first time step.
u ( xi , t ) − u ( xi , 0) ui1 − f ( xi )
g ( xi ) = ut ( xi , 0)
t t
ui1 = gi t + f i
∆t
u ( x,0) = f ( x)
t ut ( x,0) = g ( x)
x ∆x
MAFE208IU-L15 23
Example
Approximate solution of the wave equation
2u ( x, t ) 2u ( x, t )
=4 0 x 1, t 0
t 2
x 2
with boundary conditions u(0, t ) = u(1, t ) = 0, t 0
and initial conditions u ( x, 0) = sin( x),
u ( x, 0)
= 0, 0 x 1
t
at the time t=0.1 and t=0.2 using ∆x=0.2, ∆t=0.1 and compare with
exact solution
u( x, t ) = sin( x) cos(2 t )
MAFE208IU-L15 24
Solution
xi = ix = 0.2i, i = 0,1, 2,3, 4,5
tk = k t = 0.1k , k = 1, 2
u(0, t ) = u(1, t ) = 0, t 0 u0k = u5k = 0, k = 1, 2
f ( x) = sin( x), g ( x) = 0
ui1 = gi t + fi = fi = sin( xi ) = sin(0.2i ), i = 1, 2,3, 4
c 2 t 2
c =2 =1
x 2
c 2
t 2
ui2 = 2ui1 − ui0 + (u1
i −1 − 2u1
+ u1
i +1 ) = −u 0
+ (u1
i −1 + u1
i +1 )
x 2 i i
MAFE208IU-L15 25
Solution
x = [ 0 0.2000 0.4000 0.6000 0.8000 1]
At t = 0.1 :
u (0.1) = [0 0.4755 0.7694 0.7694 0.4755 0]
u1 = [0 0.5878 0.9511 0.9511 0.5878 0]
error1 = [ 0 -0.1123 -0.1816 -0.1816 -0.1123 0]
At t = 0.2 :
u (0.2) = [0 0.1816 0.2939 0.2939 0.1816 0]
u = [0 0.3633 0.5878 0.5878 0.3633 0]
2