Professional Documents
Culture Documents
How To Solve Pdes Using Mathematia and Matlab: G. Y. Park, S. H. Lee and J.K. Lee
How To Solve Pdes Using Mathematia and Matlab: G. Y. Park, S. H. Lee and J.K. Lee
2006. 5. 17
G. Y. Park, S. H. Lee and J.K. Lee
Department of Electronic and Electrical Engineering,
POSTECH
Plasma Application
Modeling POSTECH
Contents
• Solving PDEs using MATHEMATICA
- FTCS method
- Lax method
- Crank Nicolson method
- Jacobi’s method
- Simultaneous-over-relaxation (SOR) method
• Solving PDEs using MATLAB
- Examples of PDEs
Plasma Application
Modeling POSTECH
References
• Textbook
- ‘Numerical and Analytical Methods for Scientists and Engi
neers Using Mathematica’, Daniel Dubin, Wiley, 2003
Plasma Application
Modeling POSTECH
PDE (Partial Differential Equation)
PDEs are used as mathematical models for phenomena in
all branches of engineering and science.
- Three Types of PDEs:
1) Elliptic: (cu ) au f
Steady heat transfer, flow and diffusion
u
2) Parabolic: d t (cu ) au f
Transient heat transfer, flow and diffusion
2u
3) Hyperbolic: d t 2 (cu ) au f
Transient wave equation
Plasma Application
Modeling POSTECH
FTCS method for the heat equation
Heat equation in a slab
2
T ( x, t ) 2 T ( x , t ) S ( x , t )
t x
(T (0, t ) T1 (t ), T ( L, t ) T2 (t ), : thermal diffusivity )
T jn 1 T jn
T ( x j , tn )
t t
2 T jn1 2T jn T jn1
T ( x j , tn )
x 2
x 2
t n
T jn 1 T jn tS nj (T j 1 2T j
n
T j
n
1 )
x 2
Plasma Application
Modeling POSTECH
FTCS method for the heat equation
FTCS
Initial
conditions
Plot
t 0.01
Stability of FTCS and CTCS
FTCS is first-order accuracy in time and second-order accuracy in
space.
So small time steps are required to achieve reasonable accuracy.
t 0.05 Courant condition for FTCS
( unstable ) t 1
x 2
2
CTCS method for heat equation
(Both the time and space derivatives
are center-differenced.)
2 t n
T jn 1 T jn 1 2tS nj (T j 1 2T jn T jn1 )
x 2
Plasma Application
Modeling POSTECH
Lax method
Simple modification to the CTCS method
In the differenced time derivative,
Replacement by average value from surrounding grid points
(T jn 1 T jn 1 ) [T jn 1 12 (T jn11 T jn11 )]
2t 2t
The resulting difference equation is
n 1 n 1 n 1 2 t n
T j 2 (T j 1 T j 1 ) 2tS j
1 n
(T j 1 2T j
n
T n
j 1 )
x 2
Plasma Application
Modeling POSTECH
Crank Nicolson Algorithm ( Implicit Method )
BTCS ( Backward time, centered space ) method for heat equation
T jn T jn 1 tS nj x2t (T jn1 2T jn T jn1 )
a set of coupled linear equations for T jn
( This is stable for any choice of time steps,
however it is first-order accurate in time. )
Crank-Nicolson scheme for heat equation
taking the average between time steps n-1 and n,
T jn T jn 1 1
2 t (S n
j S nj 1 )
x2t (T jn1 2T jn T jn1 T jn11 2T jn 1 T jn11 )
( This is stable for any choice of time steps and second-order accurate in time. )
Plasma Application
Modeling POSTECH
Crank Nicolson Algorithm
Crank-
Nicolson
scheme
Plot
Crank Nicolson Algorithm
Plasma Application
Modeling POSTECH
Multiple Spatial Dimensions
FTCS for 2D heat equation
2 2
T ( x, y, t ) 2 2 T ( x, y, t ) S ( x, y, t )
t x y
t n t n
T jkn 1 T jkn tS njk (T j 1k 2T n
jk T n
j 1k ) (T jk 1 2T n
jk T n
jk 1 )
x 2
y 2
Plasma Application
Modeling POSTECH
Wave equation with nonuniform wave speed
2D wave equation
2 2 2
z ( x, y, t ) c ( x, y ) 2 2 z ( x, y, t )
2
t 2
x y
z ( x, y,0) z0 ( x, y ), z ( x, y,0) v0 ( x, y )
Initial condition :
z0 v0 0
Boundary z (0, y, t ) z (1, y, t ) z ( x,1, t ) 0,
condition : z ( x,0, t ) x(1 x) sin 2t
c 2jk c 2jk
a jk (z 0
j 1k 2z z
0
jk
0
j 1k ) ( z njk 1 2T jkn T jkn 1 )
x 2
y 2
Plasma Application
Modeling POSTECH
Wave equation with nonuniform wave speed
Plasma Application
Modeling POSTECH
Wave equation with nonuniform wave speed
Plasma Application
Modeling POSTECH
2D Poisson’s equation
Poisson’s equation
( 2
x 2
2
y 2
) ( x, y ) ( x, y )
Centered-difference the spatial derivatives
j 1k 2 jk j 1k jk 1 2 jk jk 1
jk
x 2
y 2
Idea :
I. Poisson’s equation can be thought of as the equilibrium solution to
the heat equation with source.
II. Starting with any initial condition, the heat equation solution will
eventually relax to a solution of Poisson’s equation.
(Maximum time step satisfying Courant
condition) 1 x 2 y 2
2 ( x, y ) ( x, y ) ( x, y, t ) 2 ( x, y ) ( x, y ) ( t )
t 2 x y
2 2
FTCS
1 x 2 y 2 1 1
jk jk
n 1 n
2
jk ( n
j 1k 2 n
jk n
j 1k ) ( n
jk 1 2 n
jk jk 1
n
)
2 x y
2
x 2
y 2
1 x 2 y 2 1 1
2
jk ( n
j 1k n
j 1k ) ( n
jk 1 jk 1
n
)
2 x y
2
x 2
y 2
Jacobi method
Simultaneous OverRelaxation (SOR)
The convergence of the Jacobi method is quite slow.
Furthermore, the larger the system, the slower the convergence.
Simultaneous OverRelaxation (SOR) :
the Jacobi method is modified in two ways,
x 2 y 2
n 1
jk (1 ) n
jk
2 x 2 y 2
1 1
jk 2 ( jn1k jn11k ) 2 ( jkn 1 jkn 11 )
x y
1. Improved values are used as soon as they become available.
2. Relaxation parameter ω tries to overshoot for going to the final result.
( 1<ω<2)
Plasma Application
Modeling POSTECH
Simultaneous OverRelaxation (SOR)
MATLAB The Language of Technical
MATLAB PDE
Computing
Plasma Application
Modeling Group
O.V. Manuilenko POSTECH
MATLAB The Language of Technical
MATLAB PDE
Computing
Plasma Application
Modeling Group
O.V. Manuilenko POSTECH
MATLAB The Language of Technical
MATLAB PDE
Computing
Run: neutrn.m >> neutrn Program to solve the neutron diffusion equation using the FTCS.
Enter time step: 0.0005 n( x, t ) 2 n ( x, t )
Enter the number of grid points: 61 n( x, t )
Enter system length: 2 => System length is subcritical t x 2
Solution is expected to be stable
Enter number of time steps: 12000
Plasma Application
Modeling Group
O.V. Manuilenko POSTECH
MATLAB The Language of Technical
MATLAB PDE
Computing
Run: neutrn.m >> neutrn Program to solve the neutron diffusion equation using the FTCS.
Enter time step: 0.0005
Enter the number of grid points: 61
Enter system length: 4 => System length is supercritical
Solution is expected to be stable
Enter number of time steps: 12000
Plasma Application
Modeling Group
O.V. Manuilenko POSTECH
MATLAB The Language of Technical
MATLAB PDE
Computing
Plasma Application
Modeling Group
O.V. Manuilenko POSTECH
MATLAB The Language of Technical
MATLAB PDE
Computing
Plasma Application
Modeling Group
O.V. Manuilenko POSTECH
MATLAB The Language of Technical
MATLAB PDE
Computing
Plasma Application
Modeling Group
O.V. Manuilenko POSTECH