MAFE208IU-L15 - Parabolic and Hyperbolic Equations

Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

Chapter 6

Numerical Methods for


Partial Differential Equations
Lecture 2: Time-dependent PDEs
• Parabolic Partial Differential Equations
• Hyperbolic Partial Differential
Equations
Finite Difference Method for Parabolic Partial
Differential Equations
Approximate solution of the heat equation in one-dimensional space
u ( x, t )  2u ( x, t )
= + f ( x, t ) 0  x  l, t  0
t x 2

with boundary conditions u(0, t ) = g1 (t ), u(l , t ) = g2 (t ), t  0


and initial condition u( x,0) = u0 ( x), 0 xl

Method can be extended for multi-dimensional space


u ( x, t ) n  2 u ( x, t ) n u ( x, t )
=   i ( x, t ) +   i ( x, t ) +  ( x, t )u ( x, t ) + f ( x, t )
t i =1 xi 2
i =1 xi
x = ( x1 , x2 ,..., xn ), t  0
forMAFE208IU-L15 2
Domain of solutions of Parabolic
Partial Differential 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

Coordinates of mesh (grid) points: ( xi , tk ),


where xi = ix, tk = k t , 0  i  m, 0  k  n
MAFE208IU-L15 4
Discretization
u ( xi , tk )  2u ( xi , tk )
= + f ( xi , tk )
t x 2

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

u (0, t ) = g1 (t ) = 100 o C u (10, t ) = g 2 (t ) = 50 o C

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

= uik + 0.02(uik+1 − 2uik + uik−1 )

u11 = 0 + 0.02[0 - 2(0) + 100] = 2.0


At t = 0.1 s u12 = 0 + 0.02[0 - 2(0) + 0] = 0
u31 = 0 + 0.02[0 - 2(0) + 0] = 0
u14 = 0 + 0.02[50 - 2(0) + 0] = 1.0

u12 = 2.0 + 0.02[0 - 2(2) + 100] = 3.92


At t = 0.2 s u22 = 0 + 0.02[0 - 2(0) + 2] = 0.04
u32 = 0 + 0.02[1- 2(0) + 0] = 0.02
MAFE208IU-L15
u42 = 1 + 0.02[50 - 2(1) + 0] = 1.96 8
Exercise
Approximate solution of the heat equation
u ( x, t ) 1  2u ( x, t )
= 0  x  1, t  0
t 16 x 2
with boundary conditions u(0, t ) = u(1, t ) = 0, t  0
and initial condition u( x,0) = 2sin(2 x), 0  x 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

2nd derivative at (i, k+1/2) is computed as weighted


average of CDA values at (i, k) and (i, k+1):
 2u  2u  2u
( xi , tk +1/2 )  (1 −  ) 2 ( xi , tk ) +  2 ( xi , tk +1 ), for 0    1
x 2
x x

 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

uik +1 − uik =  (1 −  )(uik+1 − 2uik + uik−1 ) +  (uik++11 − 2uik +1 + uik−+11 )

Defines the variable-weighted implicit formula:


 k +1 1 k +1 k +1   k 1 k 
−  ui +1 + (2 − )ui + ui −1  = (1 −  )  ui +1 + ( − 2 )ui + ui −1 
k

    (1 −  ) 
t
where  = 1  i  m − 1, k = 0,1, 2,..., n − 1
(x) 2

Method is stable for any value of λ


MAFE208IU-L15 12
Simple Implicit Method
Taking θ=1 in the variable-weighted implicit
formula defines backward implicit scheme,
or simple implicit method:

−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

u (0, t ) = g1 (t ) = 100 o C u (10, t ) = g 2 (t ) = 50 o C

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

k=0: temperature at 1 second is computed as follows


AV 1 = BV 0 + C = C
Ly = C  y = (50, 5, 50/99, 2455/98)T
UV 1 = y  V 1 = (20.2041, 2.0408, 0.2041, 10.0204)T
k=1: temperature at 2 seconds is computed as follows

AV 2 = BV 1 + C = D = (3960/49, 400/49, 40/49, 1964/49)T

Lz = D  z = ( 3960/49, 796/49, 833/339, 3912/97 )T


UV 2 = z  V 2 = (32.9929, 6.6639, 0.9929, 16.1319 )T
MAFE208IU-L15 19
Quiz
Approximate solution of the heat equation
u ( x, t ) 1  2u ( x, t )
= 0  x  1, t  0
t 16 x 2
with boundary conditions u(0, t ) = u(1, t ) = 0, t  0
and initial condition u ( x, 0) = sin(2 x), 0  x 1

at the time t=0.1 and t=0.2 using implicit Crank-Nicholson method


with ∆x=0.2, ∆t=0.1 and find the error. Exact solution:
− 2 t
u ( x, t ) = e 4
sin(2 x)

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 xl
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

Can’t use this for first time step.

U at initial time given by


initial condition.
ui,0 = f(xi)

∆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

U at initial time given by


initial condition

∆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 = ix = 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

error 2 = [ 0 -0.1816 -0.2939 -0.2939 -0.1816 0]


MAFE208IU-L15 26

You might also like