Вы находитесь на странице: 1из 18

Section 6: Solution of Partial Differential Equations

Partial Differential Equations


There are three general types of second -order partial differential equation which find very wide
application in engineering. They are usually known as the Poisson equation (the Laplace equation if the
RHS is zero), the heat (or diffusion) equation and the wave equation. Mathematically they are classified
as elliptical, parabolic and hyperbolic PDEs respectively. (In what follows, our independent variables are
x and y, which define a point in a 2-D Cartesian plane, and sometimes t which represents a time value.
Our unknown function is u, which in general will be a function of position (u ≡ u( x, y) )and sometimes of
one position variable and time ( u ≡ u( x , t ) ). To avoid writing lots of partial derivatives, we follow the
notation

∂ u( x, y) ∂ u( x, y ) ∂ 2 u( x, y) ∂ 2 u ( x, y)
ux = uy = uxy = u xx =
∂x ∂y ∂ x∂ y ∂ x2

Poisson Equation

In two dimensions, Poisson's equation is

∂ 2u ∂ 2u
+ = ρ ( x, y) or u xx + u yy = ρ ( x, y) .
∂ x2 ∂ y 2

In the specific case where the RHS or source term ρ( x, y) is zero, the equation is referred to as
Laplace's equation.

Diffusion Equation

If diffusion at any point is described by a diffusion parameter D (which may depend on position), then
the most general form of the diffusion equation is

∂u ∂  ∂ u
= − D 
∂t ∂ x  ∂ x

Where diffusion does not depend on position and is described at every point by a particular value or
diffusion coefficient, then the diffusion equation becomes

∂u ∂ 2u
= − D 2 or u t = − Du xx
∂t ∂x
(Note that the diffusion coefficient used here is not to be confused with the letter D used to represent a
differential operator in the chapter on finite differences).

6-1
Section 6: Solution of Partial Differential Equations

Wave Equation

The simplest form of the wave equation is the 1-D version

∂ 2u ∂ 2u
= v2 or utt = v 2 u xx
∂ t2 ∂ x2

where v is the velocity of wave propagation.

General Form

These three equations can be expressed in a single general form

(
A u xx + 2 B u xy + C u yy = F x , y , u, u x , u y )
where
if AC − B 2 > 0 the PDE is elliptic, e.g. Laplace equation,
if AC − B 2 = 0 the PDE is parabolic, e.g. diffusion equation,
if AC − B 2 < 0 the PDE is hyperbolic, e.g. wave equation.

From a computational point of view, the most important distinction that we can draw is between the
wave and diffusion equations on one hand and Poisson/Laplace on the other. The wave and diffusion
equations are the central aspects of initial-value problems. That is, information on the unknown function
u is given for all positions x at an initial time value t0 . The differential equations then describe how u(x, t)
changes over time for all values of x. In contrast to this, the Poisson/Laplace equation is a central aspect
of boundary-value problems, where information on the unknown function u is supplied right around the
boundary of some region of interest. The differential equations then specify what values for u(x, y) are
compatible with these boundary conditions: we need to converge on a correct solution, rather than
propagate u forward in time as is the case with the wave and diffusion equations. The computational and
memory requirements of these two types of problems are very different.

t0

x
x0 xN

Information schematic for an initial-value problem. The black circles are


the initial values of u for all x at t = t0 . The grey circles are the
boundaries of the range of x where u is usually known for all time t. The

6-2
Section 6: Solution of Partial Differential Equations

empty circles are the unknown values of u that are determined by the
PDE. Numerical computation usually "propagates" in the direction of
increasing time from t = t 0 .

yN

y0

x
x0 xN

Information schematic for a boundary-value problem. The black circles


are the initial values of u (or sometimes initial values for the derivatives of
u) for all positions on the boundary. The empty circles are the unknown
values of u that are determined by the PDE. There is no natural
propagation of a numerical computation. Usually we are looking to
converge on a set of values for the interior points which are compatible
with the boundary values and with the PDE.

Numerical Solution of Diffusion Equations

We consider the case of a constant diffusion coefficient, and we may assume that by a suitable choice of
variables the diffusion coefficient had been set equal to 1. Usually a convenient range such as [0,1] is
chosen for the position variable x. Our initial value PDE system then becomes

ut = u xx for 0 ≤ x ≤ 1, t ≥ 0
u( x,0 ) = f ( x ) for 0 ≤ x ≤ 1 (initial condition)
u (0, t ) = u (1, t ) = 0 for t≥0 (boundary condition)

In which function f(x) is known.

Explicit Scheme

Use a simple finite difference approximation to the partial derivatives above

6-3
Section 6: Solution of Partial Differential Equations

un ,i +1 − un ,i un +1,i − 2un ,i + un −1,i



k h2

where the spatial and temporal increments are given by

xn + 1 = xn + h for 0 ≤ n ≤ N , x0 = 0, x N = 1
ti + 1 = ti + k for i ≥ 0 .

i=3
k
i=2
i=1
t0 i=0

h
x0 xN

Mesh points for the finite difference approximation to the above diffusion system.
The black circles at the bottom of the mesh ( t = t0 , i = 0 ) are samples of the
function f(x) describing the initial state of the system for all the positions
x0 ,..., x N . The grey circles all have the value zero (from the boundary condition).
The empty circles are the unknown values of u that are determined by iterating
the difference equation.

We can rewrite the difference equation to give a u value in the row i+1 in terms of u values in the row i:
un ,i +1 = (1 − 2 r ) un, i + r (un+ 1,i + un −1,i ) (H.1)
where for stability we must have
k 1
r= ≤ .
h2 2

With the difference equation (H.1), each new value in row i+1 can be calculated independently of
others, it is therefore an explicit method. Unfortunately, the stability condition implies that in order for h
to be small, k must be very small. For example, h = 01 . implies that k = 0.005 . Nevertheless, the
simplicity of the scheme means that for a small, once-off calculation, it may be useful.

A schematic representation of the iteration


scheme. Here the black circles represent
i+1 values in row i which are known, while the
k
i open circle represents the new value that is
to be inferred from the known ones by an
h iteration of the difference equation. Points
used for calculation of the spatial derivative

6-4
Section 6: Solution of Partial Differential Equations

are shown connected by a continuous line, while points involved in temporal


derivatives are shown by a dotted line.

Crank-Nicolson (implicit) Scheme

If we replace the single spatial difference taken at time row i in the original difference equation, by the
average of the spatial differences in time row i and time row i+1, than we can get a method which
removes the strict stability condition needed above:

un ,i +1 − un ,i un +1,i − 2 un ,i + un −1,i un +1,i +1 − 2un ,i +1 + un −1,i +1


≈ +
k 2h 2 2h 2

The iteration equation then becomes

( 2 + 2 r) un,i+ 1 − r (un +1,i +1 + un −1,i+ 1 ) = ( 2 − 2r )un ,i + r(un +1,i + un− 1,i ) .

i+1
k
i A schematic representation of the
Crank-Nicolson scheme. The values in
h time row i+1 are unknown in general,
but must be compatible with
neighbouring calculations.

We can see from the schematic representation of Crank -Nicolson that the values on the left side of the
iteration equation (time row i+1) are in general unknown, while those on the right side of the iteration
equation (time row i) are in general known. What we don't know, however, is how to apportion the
results of the calculation in time row i among the three terms in time row i+1. The solution to this
problem is to realise that calculations at this position are not independent of calculations at neighbouring
positions. The iteration equation for position n is a linear equation in three unknowns: u n +1, i+1 , u n ,i +1 and
un −1,i +1 . With N +1 spatial samples at x 0 , x1 , ..., x N , two of which are boundary points, we have N-1
versions of the iteration equation for the N-1 unknown values in row i+1, that is u1, i+ 1 ,..., u N −1,i +1 .
This system of N-1 equations in N-1 unknowns can be solved to find the unique set of u values for time
row i+1, and so on for each subsequent row. Because the solution for each mesh point on a single row
depends on the solution for other points on that row, this type of scheme is referred to as an implicit
scheme. Where each new value can be calculated independently of others, as in the first method above,
the scheme is said to be explicit.

Numerical Solution of Wave Equations

6-5
Section 6: Solution of Partial Differential Equations

By a judicious choice of variables, (a linear transformation from any real problem that we might
encounter) we can assume that the velocity of propagation v is unity and that the spatial range of the
problem is the interval [0,1]. Then a typical wave system might be described by

utt = u xx for 0 < x < 1, t > 0


u( x,0 ) = f ( x) for 0 < x < 1 (initial displacement)
ut ( x,0) = g ( x) for 0 < x < 1 (initial velocity)
u (0, t ) = u(1, t ) = 0 for t > 0 (boundary condition)

It is straightforward to get a difference equation

un ,i +1 − 2 un ,i + un ,i −1 un +1,i − 2un ,i + un −1,i



k2 h2

where as before, h is the increment in position and k is the increment in time. We can rewrite this as an
explicit calculation of the unknown u value in time row i+1 in terms of known u values from the
previous two time rows

u n ,i+ 1 = ( )
r un +1,i + un −1,i + 2 (1 − r ) un ,i − un ,i −1
k2
where r = 2 .
h

It can be shown that this differencing scheme is stable for 0 < r ≤ 1 , so it is possible to choose r = 1 and
thus simplify the iteration formula to the following

u n, i + 1 = un +1,i + un− 1,i − un ,i − 1 .

A schematic representation of the general scheme is illustrated below. In the special case of r = 1 , the
centre dot in time row i is omitted as this is not included in the calculation.

i+1
k
i
A schematic representation of a simple
i-1
differencing scheme for a second order
h hyperbolic system.

The next most interesting aspect of this approach is how to get the iteration formula started, because it
involved two time rows in the calculation of a value in a third, and we have two sets of initial conditions
to contend with. The basic idea is to relate the given samples of the time-derivative of u, namely g( xn ) ,
to finite differences of u which involve samples from the unknown time rows for negative time. Thus

6-6
Section 6: Solution of Partial Differential Equations

un ,1 − u n, − 1
≈ g( xn ) = gn ⇒ u n , − 1 = un ,1 − 2 k g n .
2k

Our iteration equation for the zeroth time row then becomes

u n, 1 = un + 1, 0 + un − 1, 0 − un ,1 + 2 kg n or u n, 1 = 1
2 (u
n + 1, 0 + un − 1, 0 ) + kg n

Exercise:
Consider the case of an ideal elastic string, fixed to supports at each end (the boundary condition),
which has an initial shape profile given by f ( x ) = sin(π x ) (the initial displacement) and which is
initially stationary (the initial velocity is zero). We assume that the constant describing the speed of
propagation of waves in this model of the physical system has been normalised to unity. The
hyperbolic (wave) PDE model is as follows

utt = u xx for 0 < x < 1, t > 0


u( x,0 ) = sin( π x) for 0 < x < 1 (initial displacement)
ut ( x,0) = 0 for 0 < x < 1 (initial velocity)
u (0, t ) = u(1, t ) = 0 for t > 0 (boundary condition)

The initial state, just before the string is released to act or vibrate freely is illustrated below:

Using space and time increments h=k=0.1, calculate the movement of the elastic string over the
next 10 seconds. (Note It would be difficult to hold the string in this shape before letting it go: we
would not be able to do it by holding it with our fingers at one point only. One way would be to
support the string with some sort of former and imagine that this is instantaneously whipped away
to let the string vibrate freely. Computationally of course, this is not a problem. We can set the
"string" up any way we like).

The analytical solution of the problem is

u( x, t ) = sin(π x) cos( π t ) .

Use Matlab to draw a mesh plot of this solution in two dimensions (one space, one time). Try it
also as a one -dimensional spatial plot animated in time.

6-7
Section 6: Solution of Partial Differential Equations

Numerical Solution of Poisson/Laplace Equations

With elliptic PDEs we are trying to solve a second order PDE containing spatial variables and spatial
derivatives only, over some spatial region bounded by a given boundary. In addition, the solution must
satisfy some conditions on this boundary. There are three possibilities. (i) The solution must have
particular values on the boundary  this is referred to as a Dirichlet boundary condition. (ii) The
derivative of the solution must have particular values on the boundary  this is referred to as a Neumann
boundary condition. (iii) On certain parts of the boundary the solution value is specified, while on other
parts the values for the derivative of the solution are specified  this is referred to as a mixed boundary
condition. Initially we consider only Dirichlet conditions.

A commonly occurring elliptic PDE in engineering applications is Poisson's equation in two dimensions:
∇2 u = u xx + u yy = ρ ( x, y) .

Even more commonly, we meet applications where the RHS of this equation (the source term ρ ( x , y ) )
is zero, in other words Laplace's equation.

As before, our starting point can be a Taylor expansion, or the finite difference formulae derived from it
(for simplicity we assume that we have an equal increment h in both x and y directions):

un +1,m − 2un , m + un −1,m un , m+1 − 2u n ,m + un , m−1


u xx + u yy ≈ 2
+ .
h h2

Then we can immediately get a finite difference formula for Poisson's equation:

un+1,m + un−1,m + un, m+1 + un,m−1 − 4un,m = h 2 ρn,m .

It is convenient to represent the pattern of differences on the LHS of this equation by the finite difference
Laplacian operator
 1 
 
 1 − 4 1
 
 1 

or schematically as shown below.

m+1 A schematic representation of the


h differencing scheme used in the solution
of Laplace and Poisson equations. The
m
centre point is indicated as the unknown,
though usually all of the points are
m-1 unknown.
n-1 n n+1

6-8
Section 6: Solution of Partial Differential Equations

If the source value at any point is zero (and it is zero at every point in the solution of Laplace's equation),
then we can interpret the above differencing scheme as indicating that the value of the solution function
u nm at any point, equals the average of the four neighbouring mesh points. This is sometimes referred to
as the average value theorem. This average value theorem can be extended to Laplaces’s equation in
more variables.

So, our solution function unm for all values of n and m must satisfy this averaging condition relating the
value of each point with its neighbours, though, to start with, we know none of the interior mesh point
values, just those that lie on the boundary. As in the Crank-Nicolson case above, the differencing
scheme does however implicitly constrain the solution. For an N × M rectangular mesh, we have
( N − 1) × ( M − 1) equations in ( N − 1) × ( M − 1) unknowns. Unfortunately, even for a relatively small
100 × 100 mesh, we have 10,000 equations in 10,000 unknowns! With a little care Matlab can handle
something this big, but not anything substantially bigger. All is not lost, however. Because each point is
only directly related to its four immediate neighbours, the matrix of coefficients is sparse and a solution
method such as the Gauss-Sidel method will give good results.

Exercise : How would you order the mesh points in order to give the matrix of equation coefficients a
diagonal band structure? How would this help with storage requirements?

ADI Method

It is possible to reduce the size of the linear equation solution problem using a method which is part
implicit (involving the solution of linear equations) and part iterative. This is the alternating direction
implicit (ADI) method. Now, in principle all the interior mesh points are unknown until they are actually
calculated. The idea of the ADI approach is to differentiate between terms in the finite difference
equations so that some are considered to be known (presumably from a previous iteration) and the
remaining ones are unknown, but lie along the same row (or alternatively along the same column). For
the Laplace case the difference equations can be written as

un +1,m − 4un , m + un −1,m = −un , m+1 − un ,m −1

where the terms on the LHS belong to the same row (row m) while those on the RHS just belong to
column n. Equally, the difference equations can be written as

un , m+1 − 4u n ,m + un ,m −1 = −u n +1 ,m − un −1,m

where now the terms on the LHS belong to the same just one column (column n) while those on the
RHS belong just to row m. If we assume that we know the values on the RHS of the first equation, then
the values on the LHS define a set of (N-1) implicit equations for the (N-1) values in a particular row
which can be solved for a more accurate set of values in that row. The procedure is to assume an
arbitrary set of initial values for all the interior mesh points. Then we solve for a new set of values for

6-9
Section 6: Solution of Partial Differential Equations

each row in turn based on these initial values and the boundary values, where each row calls for the
separate solution of a set of (N-1) linear equations (using the first form of the difference equation above).
We then use these newly calculated mesh values to set up a system of (M-1) implicit equations for each
column in turn (the second form of the difference equation above) and solve for a new set of (M-1)
values for each column. Our iteration continues to alternate in this way between updating each row in
turn and then using these values to update each column in turn and going back to the rows, and so on.

This method is computationally less expensive for each iteration than the once-off solution of
( N − 1) × ( M − 1) linear equations required in the first approach, but it must be iterated, so the amount
of calculation will continue to grow until you are satisfied with your solution. You could greatly reduce
the number of iterations by making a good selection of initial values for the mesh points before the
iteration starts. The process then converges much more quickly than with an random set of initial values
or with all the initial (interior) mesh values set to zero. A method for selecting a "good" set of initial values
for iteration purposes is described with the next approach below, which is an entirely iterative approach.

h h
m+1
m
m-1
n-1 n n+1 n-1 n n+1

A schematic representation of the row (left) and column (right) alternative directions for the
ADI scheme used in the solution of Laplace's equation. For the case on the left, because the
unknowns are assumed to belong to a single row, a series of single row implicit linear equation
systems can be formulated and solved. Similarly in the case of columns for the diagram on the
right. The black circles represent neighbouring points that are assumed to be known from a
previous iteration. In fact values are known even for the white circles from the previous
iteration, but these are ignored in favour of the new values to be calculated by this calculation.
Of course, the values that are ignored in this row (or column), participate in the calculation of
new values for neighbouring rows (or columns).

Simple Iteration Method

In fact it is not necessary to go as far as the relatively sophisticated calculations used in the previous two
methods. If we concentrate on the Laplace version of the difference equation we can see that any
particular mesh value should be the average of four values arranged symmetrically around it (usually its
four immediate neighbours on a square grid)

un +1,m + un −1 ,m + un , m+1 + un ,m −1
un , m = .
4

If a particular mesh point does not have this average value, then no problem: just replace the mesh value
by a new one based on the average of its four neighbours. If we assume that all the neighbouring values
come from a previous iteration (this is not explicit in the above equation) then we can generate a whole

6-10
Section 6: Solution of Partial Differential Equations

new set of mesh values for the interior of the region of interest by doing this averaging calculation at each
point. By iterating the process to generate a series of complete new sets of values on the basis of the
immediately previous set of values, we will eventually converge on a set of values for unm which nearly
exactly satisfy the averaging condition, and thus Laplace's equation. A schematic diagram of the
individual averaging calculation is shown below.

A schematic representation of the simple


h iterative averaging scheme used in the solution
m+1 of Laplace equations. The centre point is
m indicated as unknown in this iteration. The
black circles represent mesh values at
m-1 neighbouring poin ts from the previous iteration
n-1 n n+1 which are used to calculate a new value for
the centre point at this iteration.

While this scheme will converge on the appropriate (unique) solution from any initial configuration of u
values, the iterative process converges much more quickly if a good set of initial values is chosen. A very
good initial starting set of u values can be selected by extending the averaging property out to any
symmetric set of four values around a particular position, not just its immediate neighbours. This idea is
best illustrated by an example. The first step is to make initial mesh point values (where possible) be
equal to the averages of four symmetrically distributed boundary points as shown below.

yM

y0

x0 xN

In this case the shaded circle can be set to have an initial value equal to the average
of the four boundary values indicated by the dotted lines. (The averaging property
should hold for any symmetrically distributed set of four mesh values centred around
a particular one).

6-11
Section 6: Solution of Partial Differential Equations

These values can then be used in turn, along with boundary values, to do initial estimates of further
interior mesh points, and so on until we have a rough estimate of every interior point. This is then the
starting point for the averaging process based on immediate neighbours only, described above.

yM

y0

x0 xN

Once the first interior point (dark grey circle) has been estimated, it can be used
to estimate further interior mesh values (light grey circles) in conjunction with the
boundary value s, as shown by the dotted diagonal lines.

Example 1: Laplace equation. Numerical solution method (Simple Iteration)


The Laplace equation Vxx + Vyy = 0 models the potential of an infinite length conducting trough. The
boundary potentials are as shown in the figure below. The width is equal to 1.5 times the height. The
cross section is divided into equal squares. Use the average value theorem and the iteration method to
determine potentials of each interior corner.

V0 = 100 (V)
Cap Conductor
y
50 (V)
V16 V17 50 (V)
V11 V12 V13 V14 V15

Gap V21 V22 V23 V24 V25 V26 V27


Gap
V=0 V32 V34 V35 V36 V=0
V31 V33
V37

V41 V42 V43 V44 V45 V46 V47

V51 V52 V53 V54 V55 V56 V57


x

Conductor V=0

6-12
Section 6: Solution of Partial Differential Equations

Rectangular trough for the evaluation of potential through the use of


the numerical solution method (iteration). The potential have be row-
column subnotations as used in a matrix

Although the initial approximation of potentials for each interior corner can be set equal to zero, better
initial potential approximations will yield a final solution in fewer iterations.

A good initial approximate potential for V33 is found by using the large diagonal of the above figure, with
the following results:
V15 + V55 + V51 + V11 100 + 0 + 0 + 50
V33 = = = 37.5 V
4 4

where V11 is the gap voltage. Now, the initial approximate potentials for V22 and V42 are obtained
through the use of smaller diagonals, yielding:

V13 + V 33 + V31 + V11 100 + 37.5 + 0 + 50


V22 = = = 46.9 V
4 4
and
V33 + V 53 + V51 + V 31 37.5 + 0 + 0 + 0
V42 = = = 94
. V
4 4

Next, the initial approximate potentials for V 24 and V44 are obtained through the use of small diagonals to
yield

V15 + V35 + V33 + V13 100 + 37.5 + 37.5 + 100


V24 = = = 688
. V
4 4
and
V 35 + V55 + V53 + V 33 37 .5 + 0 + 0 + 375
.
V44 = = = 188
. V
4 4

where V35 = V33 due to symmetry. Also due to symmetry, we find V26 = V22 and V46 = V42. The
remaining potentials V32, V23, V34, and V43 can be approximated through the average value theorem.
So we arrive at the following initial approximations. Note that, we can take advantage of symmetry, V i5
= Vi3, and Vi6 = Vi2.

V11 = 50 V12 =100 V13 =100 V14 =100 V15 =100 V16 = 100 V17 =50
V21 = 0 V22 = 46.9 V23 = 63.3 V24 = 68.8 V25 = 63.3 V26 = 46.9 V27 = 0
V31 = 0 V32 = 23.4 V33 = 37.5 V34 = 40.6 V35 = 37.5 V36 = 23.4 V37 = 0
V41 = 0 V42 = 9.4 V43 = 16.4 V44 = 18.8 V45 = 16.4 V46 = 9.4 V47 = 0
V51 = 0 V52 = 0 V53 = 0 V54 = 0 V55 = 0 V56 = 0 V57 = 0

Using these approximations, all potentials are now improved by the average value theorem to find V22,
V23, V24, V32, V33, V34, V42, V43, V44. The newest values of potential are used. Upon
completion of this round of recalculation, the iteration process is repeated starting with V22 and using the

6-13
Section 6: Solution of Partial Differential Equations

same sequence as above. This iteration process is continued until all the calculated values are stable to
the desired number of decimal places. Note that, increase the number of decimal places does not
necessarily increase the accuracy of the finial potential values. Increased accuracy can only be obtained
by increasing the number of squares. This leads to a greater number of calculations since the number of
potential points and iterations will increase.

The following Matlab program carries out the initial approximation and the iteration process:

echo on
% File: pde1.m, PDE example, Laplace equation
% Boundary condition
% final results in V, successive approximations in tmp
% number of iterations in k
echo off
v11=50;v12=100;v13=100;v14=100;v15=100;
v21=0;v31=0;v41=0;
v51=0;v52=0;v53=0;v54=0;v55=0;
% Although the initial approximations can
% be all set to zero, better initial approximations
% enable the iteration process converge faster

% Use lar ge diagonal to find good


% initial approximation to v33
v33=(v15+v55+v51+v11)/4;
v35=v33; % due to symmetry
% Use smaller diagonal to find good initial
% approximations to v22, v42, v24, and v44
v22=(v13+v33+v31+v11)/4;
v42=(v33+v53+v51+v31)/4;
v24=(v15+v35+v33+v13)/4;
v44=(v35+v55+v53+v33)/4;
% Use the average value theorm to find good initial
% approximations to v32, v23, v34, and v43
v32=(v22+v42+v31+v33)/4;
v23=(v13+v33+v22+v24)/4;
v25=v23; % due to symmetry
v34=(v24+v44+v33+v35)/4;
v43=(v33+v53+v42+v44)/4;
v45=v43; % due to symmetry

V=[v11,v12,v13,v14,v15;v21,v22,v23,v24,v25;
v31,v32,v33,v34,v35;v41,v42,v43,v44,v45;
v51,v52,v53,v54,v55]; % initial approximations
tmp(1,:)=[V(2,2:4), V(3,2:4), V(4,2:4)]; % record approximations
% Iteration
VT=V; % for comparsion of two consecutive iterations
for k=2:1000 % maximum no. of iterations allowed, 1000
for i=2:4
for j=2:4
V(i,j)=(V(i-1,j)+V(i+1,j)+V(i,j-1)+V(i,j+1))/4;
end
end
V(:,5)=V(:,3); % due to symmetry
tmp(k,:)=[V(2,2:4), V(3,2:4), V(4,2:4)]; % record approximations
delta = max(max(abs(V-VT)));
if delta < 1.e-5 break; end % results stable to 5 decimal places

6-14
Section 6: Solution of Partial Differential Equations

VT=V;
end
V(:,6)=V(:,2); V(:,7)=V(:,1); % due to symmetry

The above program gives the final result in V, which is stable to 5 decimal places, after 32 iterations.

50.0000 100.0000 100.0000 100.0000 100.0000 100.0000 50.0000


0 45.8834 61.2213 64.9810 61.2213 45.8834 0
0 22.3122 34.0206 37.4816 34.0206 22.3122 0
0 9.3449 15.0674 16.9041 15.0674 9.3449 0
0 0 0 0 0 0
0

If we set the initial approximation of potentials for each interior corner equal to zero, then it will take 38
iterations to converge to the above results, 6 more iterations than the better initial potential
approximations as in the above Matlab program.
Neumann Conditions

Neumann conditions or mixed conditions, where a value for the derivative of u normal (⊥ er) to the
∂u
boundary, , is specified on the boundary, rather than a value for u itself, are relatively straight-
∂n
forward to deal with. Suppose, for example, we are given sample values f n of a function f(x) which
∂u
describes the normal derivative along the lower (y0 ) boundary of one of the grids shown above. In
∂y
particular, this means that we do not have a boundary value for the boundary mesh point u 2,0 where
n=2 and m=0 (among others). Thus we cannot immediately use this value in the calculation of its
neighbouring interior point u 2,1 . The solution is to extend whatever evaluation scheme is being used for
interior points to include these boundary points where the value of u is unknown. In the case of a simple
iteration of the averaging formula at the point (2,0), we would thus like to evaluate

u 3, 0 + u1,0 + u2 ,1 + u2 , −1
u2 , 0 = .
4

Now, the u2 , −1 term in this formula has no given value and the iteration formula never leaves the region of
interest (plus its boundary) to specify the value for this point. Thus we need to calculate this value based
on the given Neumann boundary condition. Using a central difference formula we get

u 2 ,1 − u2 , −1 ∂u
≈ = f2
2h ∂y 2 ,0

or rearranging we get
u2 , −1 = u2 ,1 − 2hf 2 ,

so we now have all the u values we need to calculate the values along the boundaries, where the
derivative of u is given, rather than the value of u itself.

6-15
Section 6: Solution of Partial Differential Equations

Off-mesh boundaries

It is usually possible to arrange that the physical boundary that we want to model lies along mesh points
of the grid that we choose for our calculations. If not and if we need to accurately represent a physical
boundary which does not lie exactly along our grid, then we effectively have to interpolate to suitable
inter-mesh points where the boundary values of u is specified.

Consider the situation shown in the diagram below, where an irregular boundary cuts the grid between
pairs of mesh points rather than on mesh points. The distances between the internal mesh point being
evaluated (n,m ) and the boundary points at A and B are less than the usual mesh increment h.

h
An irregular non-mesh boundary is shown as a
B m+1 continuous line. It cuts the grid at points A and
h bh A B which are less than the usual grid increment
m
ah away from the mesh point at (n,m). (Adapted
m-1 from Kreyzig)
n-1 n n+1

Our tool for integrating these irregular boundary points into the calculations of the regular grid is, as
usual, Taylor's theorem, which we can use to give an expression for uA as well as un −1, m

u A = u( xn , ym ) + ah
∂u
+
(ah)2 ∂ 2 u + ...
∂x xn , ym
2! ∂ x 2 xn , ym

∂u (h )2 ∂ 2 u
un −1, m = u( xn , ym ) − h + + ...
∂x xn , ym
2! ∂ x 2 xn , ym

Multiplying the second of these expansions by a and adding, we get

∂ 2u
2
u A + aun −1,m ≈ (1 + a)u( x n , ym ) + a(1 + a ) h
2! ∂ x 2 xn , ym

which we can rewrite to give u xx evaluated at (n,m )

∂ 2u 2 1 1 1 
= 2 
uA + un −1,m − u n ,m 
∂ x2 xn , ym h  a (1 + a ) (1 + a) a 

Similarly, we can find an expression for u yy evaluated at (n,m )

6-16
Section 6: Solution of Partial Differential Equations

∂ 2u 2  1 1 1 
= 2 
uB + un ,m −1 − un ,m 
∂ y2 xn , ym h b (1 + b ) (1 + b) b 

Combining these two expressions, we have an approximation for the Laplacian operator evaluated with
the given grid and boundary points at the position (n,m)

2  uA u n , m −1  1 1  
(u ) uB u n −1,m
+ u yy = 2 
+ + + −  +  u nm 
h  a (1 + a ) b(1 + b) (1 + a ) (1 + b )  a b  
xx
xn , y m

The Laplacian operator in this case can be represented by the matrix

 1 
 b(1 + b ) 
 
 1  1 1 1 
 − +  
(1 + a )  a b a (1 + a ) 
 1 
 
 (1 + b) 

In the simple case of a=b=1/2, the operator becomes

 4
3 
2 
3 −4 3
4

 
 2
3 

Notice how the off-grid positions of the boundary values also effects how the on-grid values are included
in the Laplacian operator for this position. Note also, that all the terms sum to zero, as they must always
do.

Exercises:

1. Explain the stability condition of the explicit scheme to solve Diffusion (Heat) equations.

Answer:
This can be explained with the Courant condition for stability of a differencing scheme. The PDEs of an
initial problem imply that the value at a point depends on information within some domain of dependency
to the past, shown here shaded. A differencing scheme has it own domain of dependency determined by
the choice of points on row i (shown as connected solid dots) whose values are used in determining a
value on row i+1 (shown connected by dashed lines). A differencing scheme is Courant stable if the
differencing domain of dependency is larger than that of the PDEs as in (a), and unstable otherwise as
(b). Differencin g domain of
dependency

PDE’s domain
6-17 of dependency
Section 6: Solution of Partial Differential Equations

(a) Stable (b) Unstable

6-18

Вам также может понравиться