Introduction To PDE With FD
Introduction To PDE With FD
Introduction
In mathematics, a partial differential equation (PDE) is a differential equation that contains
unknown multivariable functions and their partial derivatives. PDEs are used to formulate
problems involving functions of several variables, and are either solved by hand, or used to
create a relevant computer model.
PDEs can be used to describe a wide variety of phenomena such as sound, heat, electrostatics,
electrodynamics, fluid dynamics, elasticity, or quantum mechanics. These seemingly distinct
physical phenomena can be formalized similarly in terms of PDEs.
Solving PDE means finding the unkown function U. An analytical (i.e. exact) solution of a PDE is
a function that satisfies the PDE and also satisfies any boundary and/ or initial conditions given
with the PDE. Most PDEs of interest do not have analytical solutions so a numerical procedure
must be used to find an approximate solution. The approximation is made at discrete values of the
independent variables and the approximation scheme is implemented via a computer program. The
FDM replaces all partial derivatives and other terms in the PDE by approximations. After some
manipulation, a finite difference scheme (FDS) is created from which the approximate solution is
obtained.
PDEs describe many of the fundamental natural laws (e.g. conservation of mass) so
describe a wide range of physical phenomena. Examples include Laplace’s equation for
steady state heat conduction, the advection- diffusion equation for pollutant transport,
Maxwell’s equations for electromagnetic waves, the Navier- stokes equation for fluid
flow and many more.
(4-a)
(4-b)
Subtract (4b) from (4a), neglect terms in 3 , 4 , …., and solve for 𝑢𝑥 . Then
(5-a)
Similarly,
(5-b)
To get second derivatives, adding (4a) and (4b) and neglecting terms in4 , 5 , …., and solve for
𝑢𝑥𝑥 . Then
(6-a)
Similarly,
(6-b)
Substitute (6a) and (6b) into the Poisson equation (3), choosing k = h to obtain a simple formula:
(7)
This is a difference equation corresponding to (3). Hence for the Laplace equation (2) the
corresponding difference equation is
(8)
his called the mesh size. Equation (8) relates u at (x, y) to u at the four neighboring points shown
in Fig. 1. It has a remarkable interpretation: u at (x, y) equals the mean of the values of u at the
four neighboring points.
Fig.2: Region in the x y – plane is covered by a grid of mesh h, also showing mesh points
𝑝11 = , , … … , 𝑝𝑖𝑗 = 𝑖, 𝑗
With this notation Eq. (8) can be written for any mesh point 𝑝𝑖𝑗 in the form:
𝑢𝑖+1,𝑗 + 𝑢𝑖−1,𝑗 + 𝑢𝑖,𝑗 +1 + 𝑢𝑖,𝑗 −1 − 4𝑢𝑖,𝑗 = 0 (10)
Example 1:
The four sides of a square plate of side 12 cm, made of homogeneous material, are kept at
constant temperature 0° 𝐶 and 100° 𝐶as shown in Fig. 3-a. Using a (very wide) grid of mesh 4
cm and find the (steady-state) temperature at the mesh points.
Solution:
The problem is a Dirichlet problem and the grid is chosen as shown in Fig. 3-b
Fig. 3: Example 1
and consider the mesh points in the order 𝑝11 , 𝑝21 , 𝑝12 , 𝑝22 as used in Eq. (10) and, in each
equation, take to the right all the terms resulting from the given boundary values. Then, obtain
the system:
−4 1 1 0 𝑢11 −200
1 −4 0 1 𝑢21 −200
1 0 −4 1 𝑢12 = −100
0 1 1 −4 𝑢22 −100
In practice, one would solve such a small system by the Gauss elimination, finding:
𝑢11 = 𝑢21 = 87.5and𝑢12 = 𝑢22 = 62.5
Example 2:
Solve, ∇2 𝑢 = −10𝑥for the shown square 3×3 with h =1 as in Fig. 4.
Fig. 4: Example 2
Solution:
−3 1 0 𝑢1 −9.5
1 −3 1 𝑢3 = −19
0 1 −3 𝑢5 −48.5
Fig. 5: Example 3
Solving the solution system, get
𝑢1 = 8.64 , 𝑢3 = 16.43 , 𝑢5 = 21.64and from symmetry, 𝑢2 = 8.64 , 𝑢4 = 16.43 , 𝑢6 = 21.64.
Quiz 1:
Using Matlab code and solve Laplace equation
for the internal mesh points with = 𝑘 = 0.5
and the boundary conditions as shown in Figure.
1.6.2 Neumann and Mixed Problem
In solving Neumann and mixed problems a new situation was appeared because there are
𝜕𝑢
boundary points at which the (outer) normal derivative 𝑢𝑛 = 𝜕𝑛 of the solution is given, but u
itself is unknown since it is not given. To handle such points we need a new idea. This idea is the
same for Neumann and mixed problems. Hence we may explain it in connection with one of
these two types of problems. We shall do so and consider a typical example as follows.
Example 4:
Solvethe mixed boundary value problem or the Poisson equation∇2 𝑢 = 𝑓 𝑥, 𝑦 = 12𝑥𝑦
in the region and for the boundary conditions as shown in Fig. 6-a
Note that:
𝜕𝑢
If the normal derivative𝑢𝑛 = 𝜕𝑥 , so
the region Rwill be extend horizontally of the external mesh points
and the Poisson equation also holds in the extended region.
the new unknowns can be rid of them by applying the central
𝜕𝑢 𝜕𝑢 𝑖,𝑗 𝑢 𝑖+1,𝑗 −𝑢 𝑖−1,𝑗
difference formula for𝜕𝑥 as following: =
𝜕𝑥 2
Quiz 2:
Solve the Poisson Equation:∇2 𝑢 = 𝑓 𝑥, 𝑦 = 2(𝑥 2 + 𝑦 2 )
With h = 1.0 in x and ydirectionand
the boundary condition as shown in the Figure.
Fig.Quiz 2
1.6.3 Irregular Boundary
If region R in the xy-planehas a simple geometric shape, then we can usually arrange for
certainmesh points to lie on the boundary C of R, and we can approximate the partial derivatives.
However, if C intersects the grid at points that are not mesh points, then at points close to the
boundary we must proceed differently, as follows.
The mesh point O in Fig. 7 is of that kind. For O and its neighbors A and P we obtain from
Taylor’s theorem
(13)
𝜕𝑢
We disregard the terms marked by dots and eliminate 𝜕𝑥0 . Equation (13 b) times a plus equation
(13 a) gives
By addition,
(14)
1 𝑏 1+𝑏
1 𝑎+𝑏 1
1 −4 1 we now have −
1+𝑎 𝑎𝑏 𝑎 1+𝑎
1 1
1+𝑏
(15)
1
1 −4 1 we now have
1
Note that:
The sum of all five terms must be zero (which is useful for checking).
Example 5:
Find the potential u in the region in Fig. 9 that has the boundary values given in that figure; here
the curved portion of the boundary is an arc of the circle of radius 10 about (0,0). Use the grid in
the figure.
Solution:
For 𝑃11 and 𝑃12 we have the usual regular stencil,
and for 𝑃21 and 𝑃22 we use (15), obtaining
1
𝑃11 , 𝑃12 : 1 −4 1
1
Fig. 9: Region, boundary values of
the potential, and grid in Example 5
0.5 0.9
𝑃21 : 0.6 −2.5 0.9 , 𝑃22 : 0.6 −3 0.9
0.5 0.6
We use this and the boundary values and take the mesh points in the usual order𝑃11 , 𝑃21 ,𝑃12 and
𝑃22 . Then we obtain the system
−4 1 1 0 𝑢11 −27
0.6 −2.5 0 0.5 𝑢21 −374.4
1 0 −4 1 𝑢12 = 702
0 0.6 0.6 −3 𝑢22 1159.2
Quiz 3:
Use Gauss elimination to solve Laplace equation
∇2 𝑢 = 0, and find the potential 𝑢 in the indicate grid
with boundary values as shown in the Figure.
Where the sloping portion of the boundary is 𝑦 = 4.5 − 𝑥
Fig.: Quiz 3
1.7 Difference Equations for the Heat Equation
In this section we explain the numeric solution of the prototype of parabolic PDEs, the one-
dimensional heat equation.
𝑢𝑥𝑥 = 𝑐 2 𝑢𝑡 (c constant).
This PDE is usually considered for x in some fixed interval, say, 0 ≤ 𝑥 ≤ 𝐿 and time 𝑡 ≥ 0and
one prescribes the initial temperature 𝑢 𝑥, 0 = 𝑓(𝑥)( f given) and boundary conditions at 𝑥 = 0
and 𝑥 = 𝐿 for all 𝑡 ≥ 0, for instance, 𝑢 0, 𝑡 = 𝑓1 , 𝑢 𝐿, 𝑡 = 𝑓2 . Then the heat equation and
those conditions are:
𝑐 2 𝑢𝑡 = 𝑢𝑥𝑥 0 ≤ 𝑥 ≤ 𝐿 , 𝑡 ≥ 0 (16)
𝑢 𝑥, 0 = 𝑓(𝑥) (Given Initial displacement)
𝑢 0, 𝑡 = 𝑓1 , 𝑢 𝐿, 𝑡 = 𝑓2 (Given Boundary conditions)
The forward difference formula of the first derivatives is given by
𝜕𝑢 𝑢 𝑖,𝑗 +1 −𝑢 𝑖,𝑗
𝑢𝑡 = = (17)
𝜕𝑡 𝑖,𝑗 𝑘
𝑘
𝑢𝑖,𝑗 +1 − 𝑢𝑖,𝑗 = 𝑢 − 2𝑢𝑖,𝑗 + 𝑢𝑖−1,𝑗
𝑐 2 2 𝑖+1,𝑗
𝑘
Let 𝑚 = , then
𝑐22
Fig. 10: Grid and mesh points in (18), (19) Fig. 11: The four points in (18), (19)
Example 6:
A rod of length 2cm is isolated well. The two ends are kept at 0 Co temperature.Find the
temperature as a function of x and t. Given 𝑐 2 = 6.6 , = 0.25 , 𝑢 𝑥, 0 = 100𝑥 0 ≤ 𝑥 ≤ 1,
𝑢 𝑥, 0 = 100 2 − 𝑥 1 ≤ 𝑥 ≤ 2. Four time steps are required.
Solution:
For 𝑚 = 0.5 , we get 𝑘 = 0.5 × 6.6 × (0.25)2 = 0.20625. The following representation of the
temperature values of the bar at initial time (at 𝑡 = 0 ) is shown
For the symmetry of the problem at node 4, we solve for the nodes 1, 2, 3, 4 only.
1-At 𝑡 = 𝑘 = 0.20625
1 1
𝑢1 = 0 + 50 = 25 , 𝑢2 = 25 + 75 = 50,
2 2
1 1
𝑢3 = 50 + 100 = 75 , 𝑢4 = 75 + 75 = 75
2 2
2-At 𝑡 = 2𝑘 = 0.4125
1 1
𝑢1 = 0 + 50 = 25 , 𝑢2 = 25 + 75 = 50,
2 2
1 1
𝑢3 = 50 + 75 = 62.5 , 𝑢4 = 75 + 75 = 75
2 2
3-At 𝑡 = 3𝑘 = 0.61875
1 1
𝑢1 = 0 + 50 = 25 , 𝑢2 = 25 + 62.5 = 43.75,
2 2
1 1
𝑢3 = 50 + 75 = 62.5 , 𝑢4 = 62.5 + 62.5 = 62.5
2 2
4-At 𝑡 = 4𝑘 = 0.825
1 1
𝑢1 =
0 + 43.75 = 21.875 , 𝑢2 = 25 + 62.5 = 43.75,
2 2
1 1
𝑢3 = 43.75 + 62.5 = 53.125 , 𝑢4 = 62.5 + 62.5 = 62.5
2 2
Quiz 4:
Solve the diffusion equation𝑢𝑥𝑥 = 𝑢𝑡 . For a thin tube 20 cm long with
𝑢 0, 𝑡 = 0, 𝑢 20, 𝑡 = 10and initial condition 𝑢 𝑥, 0 = 2(take = 4cm).Three
steps required.
1.8 Difference Equations for the Wave Equation
In this section we explain a standard method for the prototype of a hyperbolic PDE, the wave
equation:
𝜌2 𝑢𝑥𝑥 = 𝑢𝑡𝑡 (𝜌 constant).
This PDE is usually considered for x in some fixed interval, say, 0 ≤ 𝑥 ≤ 𝐿 and time 𝑡 ≥ 0 and
one prescribes the initial temperature 𝑢 𝑥, 0 = 𝑓(𝑥)( f given) and boundary conditions at 𝑥 = 0
and 𝑥 = 𝐿 for all 𝑡 ≥ 0, for instance, 𝑢 0, 𝑡 = 𝑓1 , 𝑢 𝐿, 𝑡 = 𝑓2 . Then the wave equation and
those conditions are:
𝑢𝑡𝑡 = 𝜌2 𝑢𝑥𝑥 0 ≤ 𝑥 ≤ 𝐿 , 𝑡 ≥ 0 (20)
𝑢 𝑥, 0 = 𝑓(𝑥)(Given Initial displacement)
𝑢𝑡 𝑥, 0 = 𝑔(𝑥)(Given Initial velocity)
𝑢 0, 𝑡 = 𝑓1 , 𝑢 𝐿, 𝑡 = 𝑓2 (Given Boundary conditions)
Replacing the derivatives by difference quotients as before, we obtain from (20):
1 𝜌2
𝑢𝑖,𝑗 +1 − 2𝑢𝑖,𝑗 + 𝑢𝑖,𝑗 −1 = 2 𝑢𝑖+1,𝑗 − 2𝑢𝑖,𝑗 + 𝑢𝑖−1,𝑗 (21)
𝑘2
𝜌2 𝑘 2
𝑢𝑖,𝑗 +1 − 2𝑢𝑖,𝑗 + 𝑢𝑖,𝑗 −1 = 𝑢𝑖+1,𝑗 − 2𝑢𝑖,𝑗 + 𝑢𝑖−1,𝑗
2
𝜌2𝑘2
Let 𝑚2 = , then
2
At the beginning only Equation (24) is applied then, for all the remaining
time steps, Equation (22) is applied
Example 7:
If the governing equation of the string is𝑢𝑥𝑥 = 𝑢𝑡𝑡 and the mesh grid as shown in the Figure with
= 0.2, where
𝑢 0, 𝑡 = 𝑢 1, 𝑡 = 0, 𝑢 𝑥, 0 = 𝑠𝑖𝑛𝜋𝑥, 𝑢𝑡 𝑥, 0 = 𝑔 𝑥 = 0
Find the deflection of the string at time t = 1.
Solution:
Find the displacement at time t = 0.6 and x = 0.2, 0.4, 0.6, 0.8.
Exercise
[2] For the grid in Fig. 13 compute the potential at the four internal points with
the following boundary conditions:
1) u=220 on the upper and lower edges, 110 on the left and right.
2) 𝑢 = 𝑥 4 on the lower edge, 𝑢 = 81 − 54𝑦 2 + 𝑦 4 on the right,
𝑢 = 𝑥 4 − 54𝑥 2 + 81on the upper edge, 𝑢 = 𝑦 4 on the left.
[3] Solve Poisson's equation ∇2 𝑢 = −2on a square of unit length. Each side is
divided to 4 equal parts. Find the values of the internal points that
𝑢 0, 𝑦 = 𝑢 1, 𝑦 = 𝑢 𝑥, 0 = 𝑢 𝑥, 1 = 0
[4] Solve the boundary value problem for the Poisson equation∇2 𝑢 = 2(𝑥 2 + 𝑦 2 )
in the region shown in Fig. 13and for the boundary conditions
𝑢 0, 𝑦 = 𝑢 𝑥, 0 = 0 , 𝑢 3, 𝑦 = 2𝑦 2 , 𝑢 𝑥, 3 = 9𝑥 2 .
[5] Solve the Poisson equation in problem 4 for the region and the boundary
conditions as shown in Fig. 14
4
u =100
3 4
u =0 2 3
1 1 2 u =100
1 2 3
u =0
Fig. 13 Fig. 14
1
[6] Solve ∇2 𝑢 = −𝜋 2 𝑦𝑠𝑖𝑛 𝜋𝑥 for the grid shown in Fig. 15 and 𝑢𝑦 1,3 = 𝑢𝑦 2,3 =
3
1
243 , 𝑢 = 0 on the other three sides of the square.
2
[7] Use Gauss elimination to solve Laplace equation ∇2 𝑢 = 0, and find the
potential𝑢 in the region by using the grid, with h=1 in x and y direction, and
the boundary values as shown in the Fig. 16
Fig. 15 Fig. 16
[8] In a laterally insulated bar of length 1 let the initial temperature be f (x) = x if
0 ≤ 𝑥 < 0.5 , f (x) = 1- x if 0.5 ≤ 𝑥 ≤ 1 and u(0,t) = u(1,t) = 0. Find the
temperature u(x, t) in the laterally bar with h =0.2, k = 0 after 5 steps.
[9] Solve the heat equation and let the boundary conditions be u(0,t) = u(1,t) = 0
where: f (x) = x (1- x) , h =0.1 (5 steps are required)
[10] Using the present method, solve the wave equation with h = k = 0.2
for the given initial deflection f (x) and initial velocity equal g(x) = 0
on the given t – interval , 0 ≤ 𝑡 ≤ 1 and
f(x) = x if 0 ≤ 𝑥 < 0.2 ,
f(x) = 0.25(1- x) if 0.2 ≤ 𝑥 ≤ 1
[11] Zero initial displacement. If the string governed by the wave equation
𝑢𝑡𝑡 = 𝑢𝑥𝑥 starts from its equilibrium position with initial velocity g(x) = 𝑠𝑖𝑛𝜋𝑥
, what is its displacement at time t = 0.4 and x = 0.2, 0.4, 0.6, 0.8 with h =k =0.2
Appendix A
Solving a System of Equations Using MATLAB
Left division \ : Left division can be used to solve a system of n equations written in matrix
from [a][x]= [b], where [a] is the ( n x n) matrix of coefficients, [x] is an ( n x 1) column
vector of the unknowns, and [b] is an ( n x 1) column vector of constants.
x = a\b
For example, the solution of the system of equations