Escolar Documentos
Profissional Documentos
Cultura Documentos
FACULTY OF SCIENCES
DEPARTEMENT OF APPLIED MATHEMATICS
ACADEMIC YEAR: 2009
&
NDAHIMANA RUKUNDO Janvier
Dedication
To the Almighty God, for his salvation,
To my Darling NYIRAGASIGWA Marie,
To my parents,
To my dear sisters and brothers,
And to all my friends and relatives.
BIZIMUNGU Anaclet
Dedication
To the Almighty God, for his salvation,
To the memory of my late parents,
To my dear sisters and brother,
To all my friends and relatives,
And to the member of the group (GBU).
ii
Acknowledgement
The work like this is not a fruit of two individuals. Many people were contributed to the
realization of it.
We express our sincere gratitude to Dr. NTAGANDA J. Marie for having accepted to
supervise this project. His guidance and a great number counseling he provided us
contributed to the successful completion of this work.
We would like to express our sincere thanks to all lectures of the faculty of science,
especially those of Applied Mathematics department and those of Physic department which
contributed to our formation, specially the Dean of faculty of science, Dr. NDAHAYO
Fidele, the Head of Applied Mathematics department, Dr. MINANI Froduald, lectures, Dr.
MAHARA Isidore,
Our sincere gratitude goes to our parents, brothers, and sisters especially the family of
NDAYISENGA Dogratias, the family of NTAMUKUNZI Joshua and uncle CYIZA
Prosper deserve praise for the pain and sacrifices endured during our education.
All members of our family and friend, GBU-UNR, who in one way or another, contributed to
our social and academic success we acknowledge your cares equally find our sincere thanks.
Our thanks are also expressed to the Government of Rwanda, the National University of
Rwanda, especially the department of Applied Mathematics that availed us skills for the
accomplishment of this work.
We would not forget to appreciate the company and friendship from our classmates,
roommates especially those who contributed to the completion of this work.
BIZIMUNGU Anaclet
iii
Abstract
The present work named Finite difference method for the resolution of some partial
differential equations, is focused on the resolution of partial differential equation of the
second degree.
To establish this work we have first present and classify the partial differential equations.
And follow we had present and describe the finite difference method. After we had applied
those methods for the numerical resolution of some partial differential equations.
The implementation was done using Matlab language. The result shows that the finite
difference method is very efficient for the resolution of partial differential equations, the
reason why it is useful for scientists such us engineers, physician...
Key words: Partial differential equations, finite difference method, forward difference,
backward difference, centre difference, Euler method, explicit method, implicit method, and
Crank-Nicolson method.
.
iv
Contents
Dedication.i
Acknowledgement...ii
Abstract.......iii
Content....iv
List of figures..........vi
Introduction......1
1 Presentation of partial differential equations ......................................................................3
1.1 Basic concepts and definitions........3
1.2 Classification of second order equations.....................................................................5
1.3 The canonical form ....8
1.3.1 Hyperbolic type .......8
1.3.2 Parabolic type ........10
1.3.3 Elliptic type ..11
vi
List of figures
1.1 Coordinate system....6
2.1 Grid lines....14
2.2 The slop of the chord AB ......15
2.3 Forward derivative ....16
2.4 Backward derivative.......17
2.5 The classical explicit scheme.....22
2.6 The classical implicit scheme ...23
2.7 The Crank Nicolson scheme..24
3.1 Dimensional rod of length L..27
3.2 The MATLAB function for the resolution of parabolic equation in case of
heat equation using the forward difference method...29
3.3 Forward difference method for example 3.1......30
3.4 A three dimensional representation of table given by the figure (3.3)...31
3.5 The first part of Matlab function for the resolution of parabolic equation
in case of heat equation using the Crank-Nicolson method...34
3.6 The second part of Matlab function for the resolution of parabolic
equation in case of heat equation using the Crank-Nicolson method....35
3.7 Crank-Nicolson method for example 3.3 ..36
3.8 A three dimensional representation of table given by the figure 3.7.... 37
3.9 Vibrating string..38
3.10 The MATLAB program for the resolution of the hyperbolic equation using
a three level explicit method....40
3.11 Explicit three level difference method for example 3.4...42
3.12 A three dimensional representation of the table given by the figure 3.11...43
3.13 Stead state heat flow .. 44
3.14 The computational molecule for Laplace equation..45
3.15 The MATLAB program for the resolution of the Laplaces equation.....46
3.16 Numbering system for internal grid points..47
3.17 Approximate solution for example 3.6........48
3.18 A three dimensional representation of figure 3.17...48
Introduction
We are in the generation, where, the Communication Information Technology (CIT)
completely challenges the world. According to Economy Development Poverty Reduction Strategy (EDPRS), Rwanda as a country with low natural resources, need to establish an Information Technology (IT) based economy. It is why we prefer to develop
an IT education. It is so important for all scientists to be aware to the IT.
In Applied Mathematics we also need to excel in that technology, so that we can
well solve some complex problems. So there is a need to introduce IT into mathematics courses. The use of MATLAB is integrated in such manner that is takes the
interested students and professionals, through this tool to understand the subject even
better. Note that, IT uses methods that have significant advantages over other classical
methods, because of its simplicity of analysis and computer codes, in solving problems
with complex geometries. For example Partial difference Equations (PDEs). PDEs are
equations that describe natural phenomena, and are encountered in a variety of applications in many fields, including continuum mechanics, potential theory, physics, and
geophysics, chemistry, and biology geology and mathematics economics. Note that those
problems have no relevance, if there are not solutions for them and only few of them
have analytic solutions. Also we must recognize that people who will use PDEs are not
all mathematician, so its necessary for us to develop them other methods, where they
will use computer programs to solve those problems. Therefore we need to establish
some methods that use IT to approach the given problem so that we can easily solve
them. The methods that can use IT are known as numerical methods which are techniques of writing the given problem in the language that the computer can understand.
Here we are interested in resolution of some PDEs; the problem is that the classical
methods for the resolution of PDEs present many challengers such us: much calculus;
long time to get the solution; very difficult to draw the graph solution of problem with
complex geometries; and many of the PDEs which result from engineering problems cannot be readily solved by analytical methods. Consequently, knowledge of the methods
of obtaining numerical solutions of PDEs is important to the modern engineer. As the
domain of PDEs is very large, our subject will concern with the solution of the second
order PDEs; specifically our study will carry out the resolution of the three prominent
classical equations of mathematical physics namely: the wave equation, the diffusion
equation, and the Laplaces equation.
Therefore, numerical solution of these equations is the only recourse. Its why in our
work we present, and describe the finite different methods (FDMs), which is a numerical
technique for the resolution of PDEs, and then we apply them to solve some PDEs.
Our work is organized as follows: The first chapter presents the PDEs especially
the classification of second order PDEs in the three principle classical equations of
mathematical physics. In the second chapter describe the FDMs. In this chapter we
will start by analyzing the first and the second order partial derivatives, and give the
central difference scheme, the forward and backward schemes; then we present some
schemes that use finite difference methods. In the last chapter we apply those methods
to discretize the three prominent classical PDEs. In this chapter, we give some numerical
examples for these PDEs.
Chapter 1
Presentation of partial differential
equations
In this chapter we first introduce certain basic concepts and definitions. The rest of
the chapter will be devoted to classification of linear second order differential equations
with constant coefficients into the three principal types and the corresponding canonical
forms will be discussed.
1.1
(1.1)
i,=1
in which we assume Aij = Aji And Aij , Bi , F and G are real valued functions defined
in some region of the space (x1 , x2 , ..., xn ). Here we shall be concerned with second
order PDE in one dependent variable U and two independents variables x and y hence
equation (1.2) can be put in the form
AUxx + BUxy + CUyy + DUx + EUy + F U = G,
(1.3)
(1.4)
where a, b, c, d, e and f are constants such that a, b and c are not zero simultaneously.
The lineal second order PDE with constant coefficients may be written as
AUxx + BUxy + CUyy + DUx + EUy + F U = G,
(1.5)
where A, B, C, D, E, F and G are constants such that A, B and C are not zero simultaneously. In particular we shall limit our discussion of second order equations to the
three prominent classical equations of Mathematical physics, namely
2U
2U
= f (x, t) ,
t2
x2
(1.6)
U
2U
= g (x, t) ,
t
x2
(1.7)
2U
2U
+
= h (x, y) ,
y 2
x2
(1.8)
these equations are respectively the basic PDE of wave propagation, heat equation and
potential theory. Not only are these equation of fundamental importance in many
branches of physics but they are also serve as a prototypes for the three principal types
of second-order PDEs. The kind of problems that can be solved for each of those equations and the property of the corresponding solutions are generally typical of what we
can be expected in the general case where more than two independent variables are
involved. For more detail we can refer in [1], [9].
1.2
The study of linear second-order PDE is often facilitating by recognition of the type of
the differential equation in question. For the depending on the type of the equation it
is frequently possible by mean of a coordinate transformation to reduce the equation
to one of the three canonical forms. These canonical forms correspond to differential
simple forms in which the second-order derivatives terms can appear in question. More
over the type of PDE play a decisive role in determining the kind of auxiliary conditions
that can considered with the equation so that the resolution of the problem has a unique
solution.
In this part we shall consider the classification of linear second-order PDE of equation
(1.3). In an attempt to simplify the form of second-order terms of this equation we
introduce new variables and . Consider a curve (see the figure 1.1) defined by
(x, y) = 0,
for convenience consider adjacent curves of the form
(x, y) = const,
where various values of the constant are chosen. Introduce also a family of curves
(x, y) = const,
in such a way that we can use the values of and as a local coordinate system (1.1).
In particular we require that the Jacobean
J
,
x, y
= x y y x ,
Curves
(x,y)=const.
Curves
(x,y)=const.
(1.10)
Substituting these values in equation (1.5) and collecting similar terms we have
aW + bW + cW + dW + eW + f W = g (, ) ,
(1.11)
a = A2 + 2B + C 2 ,
(1.12)
Where
b = A + B ( ) + C,
(1.13)
c = A 2 + B + C 2 ,
(1.14)
d = D + E,
e = D + E,
f = F,
and
g = G.
Using (1.12), (1.13) and (1.14) it is easy to verify that
b2 ac = (B 2 AC)( )2 ,
(1.15)
Now since the constant , , and are at our disposal we shall chose them in
such a way that at least one of the second order terms in (1.11) drop out, as matter of
facts, we shall show that according to B 2 AC > 0, B 2 AC = 0 and B 2 AC < 0.
The constant , , and can be chosen such that:
From (1.12) we have, a = c = 0,
From (1.13) we have, b = c = 0,
From (1.14) we obtain, a = c and b = 0.
Thus simplifying the equation to one of the three canonical forms we have:
W = H(W, W , W , , ),
W W = H(W, W , W , , ),
(1.16)
W = H(W, W , W , , ),
(1.17)
W + W = H(W, W , W , , ),
(1.18)
where H is a function of the new dependent variable W and his first partial derivatives,
and the new independents variables and .
Definition 1.2
We say that the PDE (1.5) is
1.3
We now consider the problem of choosing the constant , , and in (1.9) so that the
equation (1.11) will reduce to one of the canonical form (1.16), (1.17) and (1.18).
1.3.1
Hyperbolic type
The PDE is hyperbolic type if B 2 AC > 0, in this case we shall show that (1.9) can
be chosen such that the coefficient a and c in (1.11) vanish while b 6= 0 we therefore
consider the equations (1.12) and (1.13), if a = c = 0 then of necessity b 6= 0 and thus
equation (1.5) readily put in the canonical form (1.16) by dividing out by 2B. In this
case the transformation (1.9) may be chosen as the identity transformation = x, = y
with = = 1 and = = 0 suppose that A 6= 0 and = 0 or = 0, then from (1.12)
and (1.13) we would have = 0 or = 0. In either case the condition 6= 0 is
violated. Therefore and cannot be zero and hence equation (1.12) and (1.13) can
be written as
2
A
+ 2B
+ C = 0,
(1.19)
and
A
2
+ 2B
+ C = 0.
(1.20)
Thus in order that the coefficient a and c will vanish we shall choose , , and such
Am2 + 2Bm + C = 0.
(1.21)
B (B 2 AC) 2
m1 =
,
A
and
B + (B 2 AC) 2
m2 =
.
A
Let us choose
1
= B + (B 2 + AC) 2 ,
1
= A = B (B 2 + AC) 2 ,
and
= A.
Then
1
(1.22)
where D1 , E1 and F1 are constants. Here since the coefficient are constants the lower
order terms are expressed explicitly. This form is called the first canonical form of the
hyperbolic equation. With result from canonical form (1.16) the case A = 0, C 6= 0 can
be treated in very similar way. If we further introduce the variables 0 and 0 defined by
the equations
+
,
0 =
2
(1.23)
0 =
,
2
10
(1.24)
where D10 , E10 and F10 are constants. This form is called the second canonical form of
the hyperbolic equation. This alternative form can of cause be achieved directly from
equation (1.5) by means of the transformations
0 = Bx + Ay,
1
0 = (B 2 AC) 2 x,
(1.25)
and dividing out the result by the coefficient A(B 2 AC) which is different from zero.
1.3.2
Parabolic type
The PDE is parabolic type if B 2 AC = 0, in this case it is clear that the coefficients A
and C cannot be both zero. Suppose that A 6= 0, the case C = 0 can be treated in similar
manner. Then the quadratic equation (1.21) has only one distinct root m = B
. If we
A
can choose = B, = A and let and be any number such that say = 1
and = 0 then from (1.12)-(1.14) it follow, that a = A, b = 0 and c = 0. Here we have
used the fact that B 2 AC = 0 thus in the parabolic case the transformation
= x,
= Bx Ay,
reduce equation (1.5) to the form
W = D2 U + E2 U + F2 U + G2 (, ),
(1.26)
where D2 , E2 and F2 are constants, which result in the canonical form (1.17). In term
of the characteristic equation
Ad2y 2Bdx dy + Cd2x = 0,
we conclude that in the parabolic case there is only one family of characteristic given
by
Bx Ay = const.
1.3.3
11
Elliptic type
The PDE is elliptic type if B 2 AC < 0, here it is clear that neither A nor C can be
zero. Following the discussion in hyperbolic case, we see that since B 2 AC < 0 the
quadratic equation (1.21) has complex roots
1
B + i(AC B 2 ) 2
,
m1 =
A
and
B i(AC B 2 ) 2
m2 =
.
A
The choice
1
= B i(AC B 2 ) 2 ,
= = A,
and
=
with
1
= B + i(AC B 2 ) 2 ,
would then make the coefficients a and c of equation (1.11) vanish,with
b = 2A(AC B 2 ) > 0.
Thus under the change of variables
h
i
1
= B + i(AC B 2 ) 2 x + Ay,
h
= B i(AC B )
1
2
(1.27)
x + Ay,
(1.28)
where D3 , E3 and F3 are constant. However from (1.27) we see that and are complex
variables such that = . In order that we could have the canonical form in real
variables, we further make the change of variables (1.23) then, as is easy verified
1
W = (W0 0 + W0 0 ),
4
(1.29)
12
(1.30)
where D30 , E30 and F30 are constants. After dividing through by A(AC B 2 ). if we
substitute and from (1.27) in (1.28), we obtain the transformation (1.25), writing
and again in place of 0 and 0 the transformation (1.25) corresponding to the choice
= B,
= A,
1
= (AC B 2 ) 2 ,
and
= 0,
in (1.9) with this choice, it is easily verified from (1.11) that
a = c = (AC B 2 ),
and b = 0. Therefore, under the change of variables
0 = Bx + Ay,
1
0 = (B 2 AC) 2 x,
(1.31)
equation (1.5) can be reduced to the desired canonical form (1.14). We introduce
since B 2 AC < 0 equation (1.21) has no real integral curves. This means that an
equation (1.5) of the elliptic type has no real characteristic. For detail we can refer in
[1] and [9].
Chapter 2
Presentation of finite methods
Among different numerical techniques for solving PDEs and initial and boundary problems, the difference finite methods (FDMs) are widely used. These methods are derived
from the truncated Taylors series where a given PDE and boundary and initial conditions are replaced by set of algebraic equations that are then solved by varies well
known numerical techniques. Those methods have significant advantages over other
methods because of its simplicity of analysis and computer codes in solving problems
with complex geometric. [5].
We will discus different schemes for first and second order partial derivatives, and
then apply them to discretize the boundary and initial values problems of the second
order PDEs.
2.1
Grid lines
(2.2)
14
(i-1,j)
(i,j+1)
P (ih,jk)
(i,j)
(i+1,j)
(i,j-1)
2.2
Definition 2.1
If U is an open in Rn and K. N we denote by C k (u) the space of all functions on U
k
possessing continuous partial derivatives of order k and we set Cc (E) =
1 C (U ) .
Furthermore, for only E Rn we denote by Cc (E) the space of all C functions on
Rn whose support in compact and contained in E. If E = Rn , we shall usually omit it
in naming function spaces thus C k = C k (Rn ), Cc = Cc (Rn ). [3]
Let us consider a single valued, finite function U (x) that belongs to the class C (Rn )
then by the Taylors Theorem:
U (x + h) U (x) + hU 0 (x) +
h2 00
h3
U (X) + U 000 (x) + ...,
2!
3!
(2.3)
U (x h) U (x) hU 0 (x) +
h2 00
h3
U (X) U 000 (x) + ...,
2!
3!
(2.4)
2.3
15
In first order partial derivatives, we will discuss about three difference formula which
are: central partial difference formula, forward and backward difference formula
2.3.1
U (x + h) U (x h)
,
2h
(2.5)
the approximation relation (2.5) is known as the first-order central partial difference
formula. The figure (2.2) show the geometrical interpretation of the formula (2.5) as
the slops of the chord AB.
U
B
U(x+h)
P
U(x)
A
U(x-h)
2.3.2
U (x + h) U (x)
,
h
(2.6)
16
which known as forward difference formula because the step h was taken forwardly from
the point x. The interpretation is given by the figure (2.3)
U
t
B
U(x+h)
U(x+h)-U(x)
U(x)
X
A
x
x+h
2.3.3
2.4
2.4.1
17
U
t
B
U(x)
U(x)-U(x-h)
U(x-h)
X
0
A
x-h
(2.8)
2.4.2
18
2.4.3
Using the relation (2.7) the some previous argument permit to obtain
j
Uij Ui1
U
=
,
x
h j1
(2.11)
j
Ui Ui
U
=
.
t
k
The relation (2.11) is known as backward difference formula in two independent variables. The figure (2.3).illustrate the geometrical interpretation of backward difference.
2.5
U (x + h) + U (x h) 2U (x) + h2 U (x).
(2.12)
With a minor algebraic manipulation, the relation (2.12) could be written in the
form:
00
U (x + h) 2U (x) + U (x h)
,
(2.13)
U (x)
h2
which known as the second order central partial difference formula.
2.6
Let us consider in the case of function U (x, t) in two independent variables x and t, in
view of formula (2.13) we have central partial difference formula, forward and backward
difference formula.
2.6.1
19
2.6.2
(2.14)
When the step h and k are taken in the forward sense, from the relation (2.14) we will
obtain the following formulas:
j
j
Ui+2
2Ui+1
+ Uij
2U
=
; i = 0, 1, 2...n 2; j = 1, 2...m,
x2
h2 j+1
j+2
j
U
2Ui + Ui
2U
= i
; j = 0, 1, 2...m 2; i = 1, 2...n,
2
t
k 2j
j+2
j+2
Ui+2 Ui+2 Ui + Uji
2U
=
, i = 0, 1, 2...n 2, j = 1, 2...m 2.
xt
4hk
2.6.3
(2.15)
Let us take the step h and k in the backward sense, then the relation (2.14) permit to
obtain the following formulas [5]
j
j
Uij 2Ui1
+ Ui2
2U
=
; i = 1, 2...n 2, j = 1, 2...m,
2
x2
h
2U
Uij 2Uij1 + Uij2
=
; j = 1, 2...m 2; i = 1, 2...n,
2
t2
h
j
i2
Uij Uij2 Ui2
+ Uj2
2U
=
; i = 1, 2...n 2, j = 1, 2...m 2.
xt
4hk
(2.16)
2.7
2.7.1
20
Euler method
To establish the Euler schemes, we begin by partition the t-axis; it means that we choice
some points: t0 , t1 , t2 , ...tn , tn+1 ... such that
0 = t0 < t1 < t2 < ...tn < tn+1 ....
Suppose that
hn = tn+1 tn .
We can approximate U 0 (tn ) by
U (tn+1 ) U (tn )
.
hn
Forward Euler scheme Let us consider the notation U n = U (tn ). The forward Euler
scheme enables us to calculate U n+1 from U n , and it is so possible to determine successively U 1 , U 2 , U 2 ,... from U 0 . Forward Euler scheme is an explicit scheme because it
is use to approximate the solution U n+1 depending on the values of U n
U n+1 = U n + hn f (U n , tn ), n = 0, 1, 2...,
(2.17)
(2.18)
(2.19)
j
j
where f is the function of Ui1
, Uij , and Ui+1
.
In schematic form of the forward difference method (2.5) the solution at every point
(i, j + 1) on the (j + 1)th time level is expressed in term of the solution values at the
points (i 1, j); (i, j) and (i + 1, j) of previous time level, such method is called an
explicit method.
21
T
.
m
The corresponding point of the interval [0, L] and [0, T ] are denoted by
xi , i = 0, 1...n,
and
tj j = 0, 1...m,
respectively. The points P (xi , tj ) are called the mesh or grid points and are defined by
xi = hi, i = 0, 1...n,
tj = kj, j = 0, 1...m.
The approximated solution U (x, t) at the mesh point (xi , tj ) is denoted by Uij and the
true solution is denoted by U (xi , tj ).
To obtain the classical explicit difference formula we approximate each partial derivative of U by the central partial difference formula, the forward difference formula, or
the backward difference formula [5].
The geometrical interpretation of classical explicit method is show in figure 2.5.
2.7.2
Implicit method
In order to establish the implicit difference schemes we proceed in the same manner as
we use to approximate the explicit difference schemes, where the solution Uij+1 of the
j
j
(j + 1)th time level must depend on the values, Ui1
, Uij and Ui+1 of U at previous level
time but the implicit difference schemes cannot directly approximate Uij+1 depending
22
(i,j+1)
k
h
(i-1,j)
(i,j)
(i+1,j)
(2.20)
j
j
, Uij , and Ui+1
.
where f designates the function of Uij+1 , Ui1
Euler method
Backward Euler scheme This scheme can be expressed from the following relation
[7]
U n+1 U n
= f (U n+1 , tn+1 ), n = 0, 1, 2....
(2.21)
hn
The backward Euler scheme is an implicit scheme because it cannot directly approximate U n+1 depending on U n , if is not trivial. It is easy to see that from (2.21) we
have
U n+1 hn f (U n+1 , tn+1 ) = U n , n = 0, 1, 2....
(2.22)
23
(2.23)
j+1
j+1
, Uij+1 and Ui+1
.
where f designates the function of Ui1
The solution value at point (i, j + 1) on the (j + 1)th time level is depend on the
solution values at the neighboring points on the same level and the one point on the
j th time level. which are obtained implicitly [5]. The figure 2.6 shows the geometrical
interpretation of classical implicit backward scheme.
(i,j+1)
k
h
(i-1,j)
(i,j)
(i+1,j)
Crank-Nicolson method
It is show that this method is indispensable in PDE resolution [5]
24
(i,j+1)
k
h
(i-1,j)
(i,j)
(i+1,j)
(2.24)
(j+1)
(j+1)
(j+1)
(j+1)
U1
, U2
, ..., Un1
iT
j = 0, 1, 2...,
(2.25)
a b
A = 0 . . .
.. . .
.
.
0
0
b0 c 0
0
. . . ..
a b0
c
.
.. ..
.
.
. 0 , B = 0 . .
.. . .
.
a
b c
.
0
a b
0
0
25
..
.
c0
.. ..
.
.
0
a0
0
b0
a0
0
..
.
0
c
b0
2.7.3
The Lax-Wendroff method, named after Peter Lax and Burton Wendroff, is a numerical
method for the solution of hyperbolic partial differential equations. It is based on finite
differences. Suppose one has an equation of the following form:
V (U (x, t))
U (x, t)
=
,
t
x
(2.26)
where x and t are independent variables, and the initial state, U (x, 0) is given.
The first step in the LaxWendroff method calculates values for U (x, t) at half time
steps, tn+1/2 and half grid points xi+1/2 . In the second step values at tn+1 are calculated
using the data for tn and tn+1/2 .
First (Lax) step:
n+ 1
Ui+ 12
2
n
Uin Ui+1
2
1
t
2
n
Vi+i
Vin
=
,
x
(2.27)
Second step:
n+ 1
n+ 1
Vi+ 1 2 Vi 1 2
Uin+1 Uin
2
2
=
.
(2.28)
t
x
This method can be further applied to some systems of partial differential equations.
For detail we can refer from [2] .
Chapter 3
Numerical solution of three forms of
partial differential equations
In this chapter, we present some numerical solution for solving the three prominent
classical equations of mathematical physics namely:
1. The wave equation,
2. The diffusion equation,
3. The Laplaces equation,
presented in chapter 1, using some formulas described in chapter 2.
3.1
Parabolic equations
We begin our discussion with one-dimensional PDEs of parabolic type form (1.7). which
is diffusion equation given by the relation
Ut = Uxx , 0 < x < L, 0 < t T,
(3.1)
(3.2)
(3.3)
27
Here U (x, t) denote the Temperature at any time t along a thin rod of length L in which
heat is following as illustrated in figure 3.1. We assume that the rod is of homogeneous
material and has a cross-section at area A that is constant throughout the length of the
rod. The rod is laterally insulted along its entire length. The constant is determined
by the thermal properties of the material and is measure of its ability to conduct heat
or denotes the thermal diffusivity. For the grid (xi, tj) = (ih, jk), we will discuss the
following three finite difference schemes.
A: Area
X=0
X=L
Figure 3.1: Dimensional rod of length L.
3.1.1
Forward difference
To present this scheme, two formulas from chapter 2 are used in this context. The central
difference formula (2.14) for approximating Uxx (xi , tj ) and the forward difference formula
(2.10) for approximating Ut (xi , tj ) by using these schemes the equation 3.1 gives
j
Uij+1 Uij
U j 2Uij + Ui1
= i+1
,
k
h2
if we set =
(3.4)
k
and solve Uij+1 we will obtain the explicit difference formula
2
h
j
j
Uij+1 = (1 2)Uij + (Ui+1
+ Ui1
) i = 1, .., .n 1, J = 0, ..., m 1,
(3.5)
28
(3.7)
Once the approximations Ui1 , Ui2 , ..., Uim can be obtained in a similar manner. If n and
m are small values, for example n = 4, m = 3 the values of
Uji i = 1, ..., n; m = 1, ..., m
can be easily found manually. But if n and m are great numbers, it will be difficult to compute the values of Uji at every grid point; Here it is necessary to compute
the numerical solution using the programming languages like FORTRAN, C ++ ,Maple,
Mathematica, etc. In our work the implementation is made using Matlab.
Example 3.1
The MATLAB function for the resolution of parabolic equation in case of heat equation using forward difference method is given by the figure 3.2
We illustrate the forward difference method by solving the heat equation
Uxx = Ut , 0 < x < 1, t > 0,
subject to the initial and boundary conditions
U (x, 0) = sin(x), 0 x 1,
U (0, t) = U (1, t) = 0, t 0,
the exact solution to this problem is
2
U (x, t) = e t sin(t).
29
function heat(f,c1,c2,L,T,h,k,alpha)
% Solve the heat equation
% with I.C. u(x,0)=f(x)
% and B.C. u(0,t)=c1 and u(L,t)=c2.
% using the Forward-Difference method
n=L/h;m=T/k;
lambda=alpha*k/(h^2)
z=0:h:L;
disp('______________________________________________')
fprintf(' t
x = ')
fprintf('%4.2f
',z)
fprintf('\n')
disp('____________________________________________ _')
fprintf('% 5.4f ',0)
% Compute the values of u at t=0
for i=1:n+1
u(i)=feval(f,(i-1)*h);
fprintf('%10.6f ',u(i))
end
fprintf('\n')
% Compute the values of u t=jk, k=1,2,...,m
for j=1:m
t=j*k;
fprintf('% 5.4f ',t)
for i=1:n+1
if (i==1)
y(i)=c1;
elseif (i==n+1)
y(i)=c2;
else
y(i)=(1-2*lambda)*u(i)+lambda*(u(i+1)+u(i-1));
end;
fprintf('%10.6f ',y(i))
end;
fprintf('\n')
u=y;
end;
Figure 3.2: The MATLAB function for the resolution of parabolic equation in case of
heat equation using the forward difference method.
The solution will be approximated first with T = 0.025, h = 0.1 and k = 0.0025 so that
= hk2 = 0.25 n = Lh = 10 and m = Tk = 10.
The approximation of U at t = 0.0025 for i = 1, 2 are found in this manner; we
first replace the value of into equation (3.5) we get the simplified difference equation
j
j
Uij+1 = 0, 5Uij + 0.25(Ui+1
+ Ui1
) i = 1, .., 9; j = 0, ..., 9.
(3.8)
30
1
1
U11 = (U00 + 2U10 + U20 ) = [sin(0.0) + 2 sin(0.1) + sin(0.2)] = 0.301455,
4
4
1
1
U21 = (U10 + 2U20 + U30 ) = [sin(0.1) + 2 sin(0.2) + sin(0.3)] = 0.573401.
4
4
If we continue in this manner,we get the result show in table of the figure 3.3,which are
obtained using the MATLAB function heat given in the figure 3.2. A three dimensional
representation of table given by the figure 3.3 is shown in figure 3.4.
t \x
0.00
0.10
0.20
0.30
0.40
0.50
0.60
0.70
0.80
0.90
1.00
0.809017 0.587785
0.309017 0.000000
0.769905 0.559369
0.294078 0.000000
0.0075 0.000000 0.286881 0.545680 0.751064 0.882929 0.928367 0.882929 0.751064 0.545680 0.286881 0.000000
0.0100 0.000000 0.279861 0.532327 0.732685 0.861322 0.905648 0.861322
0.732685 0.532327
0.279861 0.000000
0.0125 0.000000 0.273012 0.519300 0.714755 0.840244 0.883485 0.840244 0.714755 0.519300 0.273012 0.000000
0.0150 0.000000 0.266331 0.506591 0.697263 0.819682 0.861865 0.819682
0.680200 0.494194
0.259813 0.000000
0.0200 0.000000 0.253455 0.482100 0.663554 0.780055 0.820198 0.780055 0.663554 0.482100 0.253455 0.000000
0.0225 0.000000 0.247253 0.470303 0.647316 0.760966 0.800127 0.760966
0.647316 0.470303
0.247253 0.000000
0.458793 0.241202
0.000000
3.1.2
To apply the classical implicit method, the finite difference equation of this method
is obtained by replacing Uxx (xi , tj ) in the equation (3.1) with the centered difference
formula (2.14) at the time steps j + 1, and Ut (xi , tj ) with the forward difference formula
(2.10), we obtain
j+1
Uij+1 Uij
U j+1 2Uij+1 + Ui1
= i+1
,
(3.9)
k
h2
31
0.8
0.6
0.4
0.2
0
0.025
0.02
1
0.015
0.8
0.6
0.01
0.4
0.005
0.2
0
Figure 3.4: A three dimensional representation of table given by the figure 3.3.
if we set =
k
for we obtain the implicit difference formula
h2
j+1
j+1
Ui1
+ (1 + 2)Uij+1 Ui+1
= Uij i = 1, ..., n 1, j = 0, ..., m 1,
(3.10)
known as the classical implicit method. In schematic form, the equation (3.10) is shown
in figure 2.6 The solution value at any point (i, j + 1) on the (j + 1)th time level is
depending on the solution values at the neighboring points on the same level and one
point on the j th time level. Since values at the (j +1)th time level are obtained implicitly,
the method is called the implicit method. The matrix form of the classical implicit
method is
AU (j+1) = U (j) , j = 0, 1, 2...
(3.11)
where
U
(j+1)
(j+1)
(j+1)
(j+1)
U1
, U2
, ..., Un1
iT
2(1 + )
..
..
.
2(1
+
)
.
...
...
A=
.
0
0
..
.
2(1 + )
2(1 + )
32
Example 3.2
We illustrate the forward difference method by solving the heat equation
Uxx = Ut , 0 < x < 0.5, t > 0,
subject to the initial and boundary conditions
U (x, 0) = cos(x), 0 x 0.5,
U (0, t) = U (0.5, t) = 0, t 0.
The solution will be approximated with T = 0.025, h = 0.1 and k = 0.0025 so that
k
= 2 = 0.25 n = 5 and m = 10, the approximation of U at t = 0.0025 are found in
h
this manner. We first replace the value of into equation (3.10) we get the simplified
difference equation
j+1
j+1
0.25Ui1
+ (1.5)Uij+1 0.25Ui+1
= Uij i = 1, .., 4; j = 0, ..., 9.
U1
U1
1.5 0.25
0
0
= ,
0
0.25 1.5 0.25 U31 U30
U40
U41
0
0
0.25 1.5
the initial conditions
U (xi , 0) = cos(xi ), i = 1, ..., 4,
are used to find the value of Ui0 for i = 1, ..., 4 and our system becomes
1.5 0.25
0
0
U1
0.99998498
0.25 1.5 0.25
U21 0.99993992
1 =
.
0
0.25 1.5 0.25 U3 0.99986485
0
0
0.25 1.5
U41
0.999975974
The solution of the tridiagonal system is
U (xi , 0, 0025) = [0.82756606, 0.965456227, 0.965411405, 0.827552586]t , i = 1, .., 4
and the other values of U (xi , 0, 005), ..., U (xi , 0, 05) are found in the similar manner.
For simplifying many iterations it is important to compute the values of Uji for
i = 1, ..., n;
and
j = 1, ..., m
using the programming languages [4].
3.1.3
33
The Crank-Nicolson method, is based on the finite difference equation. This equation is
obtained by replacing Uxx (xi , tj ) of the equation (3.1) with the average of the centered
difference formula (2.14) at the time steps j + 1, and j, then Ut (xi , tj ) with the forward
difference formula (2.10), which gives
"
#
j
j
j
j+1
j+1
j+1
Uij+1 Uij
Ui+1 2Ui + Ui1 Ui+1 2Ui + Ui1
=
+
i = 1, ..., n 1 , (3.12)
k
2
h2
h2
if we set =
k
as before, equation (3.12) can be written as
h2
j+1
j
j
j+1
+2 (1 + 2) Uij+1 Ui+1
= Ui1
+2 (1 2) Uij +Ui+1
i = 1, ..., n1, (3.13)
Ui1
known as the Crank-Nicolson method. In schematic form, the equation (3.13) is shown
in figure 2.7. The solution value at any point (i, j + 1) on the (j + 1)th time level
is depending on the solution values at the neighboring points on the same level and
three points on the j th time level. Since values at the (j + 1)th time level are obtained
implicitly, the method is called the implicit method.
The matrix form of the Crank-Nicolson method is
AU (j+1) = BU (j) , i = 0, 1, 2...
where
U
(j+1)
(j+1)
(j+1)
(j+1)
U1
, U2
, ..., Un1
(3.14)
iT
2(1 + )
..
.
2(1 + ) . .
.
.
.
.
.
A =
,
.
.
0
0
.
.
2(1
+
)
2(1 + )
2(1 )
..
.
2(1 ) . .
.
.
.
.
.
B =
.
.
0
0
..
2(1 )
2(1 )
The MATLAB function for the resolution of parabolic equation in case of heat equation
using the Crank-Nicolson method is is given in the figure 3.5 and the figure 3.6
34
function heat_crank(f,c1,c2,L,T,h,k,alpha)
% Solve the heat equation with I.C. u(x,0)=f(x) and B.C. u(0,t)=c1, and
%u(L,t)=c2, using Crank-Nicolson method.
n=L/h;m=T/k; lambda=alpha*k/(h^2)
z=0:h:L;
disp('______________________________________________')
fprintf(' t
x = ')
fprintf('%4.2f
',z)
fprintf('\n')
disp('______________________________________________')
fprintf('% 4.2f ',0)
% Compute the values of u at t=0
for i=1:n+1
u(i)=feval(f,(i-1)*h);
fprintf('%10.6f ',u(i))
end
fprintf('\n')
for i=2:n
if (i~=n)
% Compute the subdiagonal of A.
a(i)=-lambda;
end
% Compute the main diagonal of A.
b(i)=2*(1+lambda);
if (i~=n)
% Compute the superdiagonal of A.
c(i)=-lambda;
end
end
Figure 3.5: The first part of Matlab function for the resolution of parabolic equation in
case of heat equation using the Crank-Nicolson method.
Example 3.3
Solve the heat equation
Uxx = Ut , 0 < x < 1, 0 < t < 0.5,
subject to the initial and boundary conditions
U (x, 0) = sin(x), 0 x 1,
U (0, t) = U (1, t) = 0, 0 < t < 0.5.
We choose h = 0.2, k = 0.05, so that = 1.25, n = 5, and m = 10 by replacing the value
of into equation (3.13) we get the simplified difference equation
j+1
j+1
j
j
1.25Ui1
+ 4.5Uij+1 1.25Ui+1
= 1.25Ui1
+ 0.5Uij + 1.25Ui+1
i = 1, ..., 4.
35
Figure 3.6: The second part of Matlab function function for the resolution of parabolic
equation in case of heat equation using the Crank-Nicolson method.
At the first time step t = k, Ui1 is given by the solution of the tridiagonal system
1
0.5U10 + 1.25U20
U1
4.5 1.25
0
0
1.25U 0 0.5U 0 + 1.25U 0
1.25 4.5 1.25
0
U21
1
2
3
1 =
0
0
1.25U2 0.5U3 + 1.25U40
0
1.25 4.5 1.25 U3
1.25U30 0.5U40
0
0
1.25 4.5
U41
0.894928
1.448024
1.448024
0.894928
where
Ui0 = sin(ih).
The solution to the tridiagonal system is
U (xi, 0.05) = [0.36122840, 0.58447983, 0.58447983, 0.36122840]T , i = 1, 2, 3, 4.
Using the MATLAB function heat crank, we obtain the solution shown in table given by
the figure 3.7 and three dimensional representation of this is shown in figure 3.8
t\ x
0.00
0.00
36
0.20
0.000000
0.40
0.587785
0.951057
0.60
0.951057
0.80
0.587785
1.00
0.000000
0.05
0.000000
0.361228
0.584480
0.584480
0.361228
0.000000
0.10
0.000000
0.221996
0.359197
0.359197
0.221996
0.000000
0.15
0.000000
0.136430
0.220748
0.220748
0.136430
0.000000
0.20
0.000000
0.083844
0.135662
0.135662
0.083844
0.000000
0.25
0.000000
0.051527
0.083372
0.083372
0.051527
0.000000
0.30
0.000000
0.031666
0.051237
0.051237
0.031666
0.000000
0.35
0.000000
0.019461
0.031488
0.031488
0.019461
0.000000
0.40
0.000000
0.011960
0.019351
0.019351
0.011960
0.000000
0.45
0.000000
0.007350
0.011893
0.011893
0.007350
0.000000
0.50
0.000000
0.004517
0.007309
0.007309
0.004517
0.000000
3.2
Hyperbolic equations
In this section we will discuss methods for the numerical solutions of the on-dimension
PDEs of hyperbolic type. Consider the wave equation given by form of equation (1.6)
that is
Utt = 2 Uxx , 0 < x < L, t > 0,
(3.15)
(3.16)
(3.17)
Here U (x, t) denotes the vertical displacement of a uniform, perfectly flexible string
of a contact density that is tightly stretched between two fixed points, 0 and L, we
assume that the equilibrium position of the string is horizontal, with the string aligned
along the x-axis as shown in figure 3.9. Suppose that the string is plucked at time t = 0
37
0.8
0.6
0.4
0.2
0
0.5
0.4
1
0.3
0.8
0.6
0.2
0.4
0.1
0.2
0
x
t
Figure 3.8: A three dimensional representation of table given by the figure 3.7.
causing the string to vibrate. Our problem is to determine the vertical displacement
U (x, t) of a point x at time t. We assume that the horizontal displacement is so small
relative to the vertical displacement as to be negligible we also assume that the maximum
displacement of each point on the string is small in comparison with the length L of the
string.
We assume that the region R = {(x, t)|0 x L, 0 t T } to be subdivided
into rectangles as show in the figure 2.1. To derive a difference equation for the solution
we start by replacing the space derivative by the center difference formula but more
frequently used schemes are the explicit schemes and the implicit schemes of Crank
Nicolson.
3.2.1
Implicit scheme
In the Crank-Nicolson scheme, we start by replacing the space derivative Uxx (xi , tj ) by
the average of the central difference formula at the time steps j + 1 and j 1; and the
time derivative Utt (xi , tj ) by the central difference formula. the result is
"
#
j+1
j+1
j+1
j1
j1
Ui+1
2Uij1 + Ui1
Uij+1 2Uij + Uij1
2 Ui+1 2Ui + Ui1
=
+
. (3.18)
k2
2
h2
h2
38
U: displacement
3.2.2
Explicit scheme
We start by replacing the space derivative by the center difference formula and the time
derivative by the center difference formula (2.14) into (3.15) gives the difference equation
!
j
j
j
U
2U
+
U
Uij1 2Uij + Uij1
i+1
i
i1
= 2
.
(3.20)
k2
h2
39
k
If we set = 2 and rearrange the order of the terms, we obtain the explicit three
h
level difference formula
j
j
Uij+1 = 2 1 2 Uij + 2 (Ui1
+ Ui+1
) Uij1 , i = 1, ..., n 1 j = 0, ..., m 1. (3.21)
In schematic form the equation (3.21) is shown in figure 2.5. The solution at every point
(i, j + 1) on the (j + 1)th time level is expressed in term of the solution values at the
points (i 1, j), (i, j), (i + 1, j) and (i, j 1) of the two previous time levels. The
explicit formula (3.21) has a stability problem and it can be shown that the method is
stable if 0 < 1 [4].
The right-hand side of equation (3.21) show that to calculate the entry Uij+1 on the
(j + 1)th time level, we must use entries from the j th and (j 1)th time levels. this
requirement creates a problem at the beginning because we only know the very first
row from the initial condition Ui0 = f (xi ). To obtain the second row corresponding to
Ui1 , the second initial condition Ut (x, 0) = g(x) may be used as follows. If we use the
forward difference approximation
Ut (xi , 0)
U (xi , t1 ) U (xi , 0)
,
k
(3.22)
we get a finite difference equation that gives an approximation for the second row. To
get a better approximation, we consider the Taylor series expansion of U (x, t) about the
point(xi , 0).
k2
U (xi , k) U (xi , 0) + kUt (xi , 0) + Utt (xi , 0).
(3.23)
2
Assuming that the second derivative of f (x) exists, we have the result obtained from
the equation (3.15) and (3.17)
Utt (xi , 0) = 2 Uxx (xi , 0) = 2 f 00 (xi ),
(3.24)
substituting (3.24) into (3.23) and using the initial condition (3.17)
Ut (xi , 0) = g(xi )
U (xi , 0) = f (xi )
we have
U (xi , k) f (xi ) + kg(xi ) +
(3.25)
k 2 2 00
f (xi ).
2
(3.26)
40
Finally by replacing f 00 (xi ), in the last equation, by the central difference formula, we
get a difference formula for the numerical approximation in second row
k 2 2
[f (xi1 ) 2f (xi ) + f (xi+1 )] ,
2h2
2
Ui1 (1 2 )f (xi ) + kg(xi ) +
[f (xi1 ) + f (xi+1 )] ,
2
(3.27)
where
k
.
h
The MATLAB program for the resolution of the hyperbolic equation using a three level
explicit method is given by the following figure 3.10
=
function hyperbolic(f,g,c1,c2,L,T,h,k,alpha)
% Solve the hyperbolic equation
% with u(x,0)=f(x), ut(x,0)=g(x).
% and u(0,t)=c1 and u(L,t)=c2,
% using a three level explicit method.
n=L/h;m=T/k;
lambda=alpha*k/h
z=0:h:L;
disp('_______________________________________________')
fprintf(' t
x = ')
fprintf('%4.2f
',z)
fprintf('\n')
disp('________________________________________________')
fprintf('% 4.2f ',0)
% Compute the values of u at t=0
for i=1:n+1
u0(i)=feval(f,(i-1)*h);
fprintf('%10.6f ',u0(i))
end
fprintf('\n')
fprintf('% 4.2f %10.6f ',k,c1)
%Compute the values of u at t=k
for i=1:n-1
u1(i+1)=(1-lambda^2)*feval(f,i*h)+lambda^2/2*(feval(f,(i+1)*h)...
+feval(f,(i-1)*h))+k*feval(g,i*h);
fprintf('%10.6f ',u1(i+1))
end
fprintf('%10.6f ',c2)
fprintf('\n')
%Compute the values of u at t>k
for j=2:m
t=j*k;
fprintf('% 4.2f ',t)
%Boundary condition
u1(1)=c1; ui(1)=c1; u1(n+1)=c2; ui(n+1)=c2;
fprintf('%10.6f ',ui(1))
for i=2:n
ui(i)=2*(1-lambda^2)*u1(i)+lambda^2*(u1(i+1)...
+u1(i-1))-u0(i);
fprintf('%10.6f ',ui(i))
end
fprintf('%10.6f ',ui(n+1))
fprintf('\n')
u0=u1;
u1=ui;
end
Figure 3.10: The MATLAB program for the resolution of the hyperbolic equation using
a three level explicit method.
41
Example 3.4
Using the explicit scheme (Forward difference), approximate the solution of the wave
equation
16Uxx = Ut , 0 < x < 1, t > 0,
subject to the conditions
U (x, 0) = sin(x), 0 x 1,
Ut (x, 0) = 0, 0 x 1,
U (0, t) = U (1, t) = 0, t > 0.
The solution will be approximated with T = 0.5, h = 0.2, and k = 0.05, so that
=
0.05
k
=4
= 1.0,
2
h
0.2
t \ x 0.00
0.00
42
0.20
0.000000
0.587785
0.40
0.951057
0.60
0.951057
0.80
1.00
0.587785
0.000000
0.05
0.000000
0.475528
0.769421
0.769421
0.475528
0.000000
0.10
0.000000
0.181636
0.293893
0.293893
0.181636
0.000000
0.15
0.000000
-0.181636
-0.293893
-0.293893
-0.181636
0.000000
0.20
0.000000
-0.475528
-0.769421
-0.769421
-0.475528
0.000000
0.25
0.000000
-0.587785
-0.951057
-0.951057
-0.587785
0.000000
0.30
0.000000
-0.475528
-0.769421
-0.769421
-0.475528
0.000000
0.35
0.000000
-0.181636
-0.293893
-0.293893
-0.181636
0.000000
0.40
0.000000
0.181636
0.293893
0.293893
0.181636
0.000000
0.45
0.000000
0.475528
0.769421
0.769421
0.475528
0.0000 00
0.50
0.000000
0.587785
0.951057
0.951057
0.587785
0.000000
Figure 3.11: Explicit three level difference method for example 3.4.
3.3
Elliptic equation
Our discussion on elliptic equations will focus on the formulation of the finite difference
equation for the two dimensional Laplace equation given by equation
Uxx + Uyy = 0,
(3.28)
on rectangular domain
R = {(x, y)| a < x < b, c < y < d},
and subject to the Dirichlet boundary condition
U (x, c) = f1 (x), U (x, c) = f2 (x), a x b,
U (a, y) = g1 (x), U (b, y) = g2 (y), c x d.
(3.29)
43
0.5
-0.5
-1
0.5
0.4
1
0.3
0.8
0.6
0.2
0.4
0.1
x
0.2
0
Figure 3.12: A three dimensional representation of the table given by the figure 3.11.
region R, as illustrated in the figure 3.13. This situation is modelled with Laplaces
equation in R with the boundary condition (3.29)
To solve the Laplaces equation by finite difference methods, the region R is partitioned into a grid consisting of n m rectangles with sides h and k. The mesh points
are given by
xi = a + ih, i = 1, .., .n,
(3.30)
yj = c + jk, J = 0, ..., m.
By using central difference approximation for the spatial derivatives, the finite difference
equation for equation (3.29) is
j
j
Ui+1
2Uij + Ui1
Uij+1 2Uij + Uij1
+
= 0, i = 1, ..., n 1, j = 0, ..., m 1, (3.31)
h2
k2
and the boundary conditions are
(3.32)
after it is desirable to set h = k and in this case the equation (3.31) becomes
j
j
4Uij + Uij1 + Uij+1 + Ui1
+ Ui+1
= 0.
(3.33)
44
Y
f2(x)
d
Uxx+Uyy=0
g1(x)
g2(x)
f1(x)
45
(i-1,j)
h
(i,j+1)
P (ih,jk)
(i,j)
(i+1,j)
h
4 1
0
1
0
0
0
0
0
V1
U0,3 + U1,4 = 300
1 4 1
0
1
0
0
0
0
V2 U2,4 = 100
0
1 4 0
0
1
0
0
0 V3 U4,3 + U3,4 = 400
1
0
0 4 1
0
1
0
0 V4 U0,2 = 200
0
V5 =
1
0
1
4
1
0
1
0
0
0
0
1
0
1
4
0
0
1
V
U
=
200
4,2
0
0
1
0
0
4
1
0
V
U
U
=
500
7
0,4
1,0
0
V U = 300
0
0
0
1
0
1
4
1
8
2,0
0
0
0
0
0
1
0
1 4 V9
U3,0 + U4,1 = 400
46
function laplace(f1,f2,g1,g2,a,n,itmax,tol)
% Solve the laplace equation in a square
% with B.C. u(x,0)=f1(x), u(x,a)=f2(x)
% and u(0,y)=g1(y) and u(a,y)=g2(y).
% using the five point difference method.
% Gauss-Seidel method is used to solve the linear system.
h=a/n;
z=0:h:a;
h
disp('__________________________________________________')
fprintf(' u= x\\y ')
fprintf('%4.2f
',z)
fprintf('\n')
disp('__________________________________________________')
for i=1:n+1
u(i,1)=feval(f1,(i-1)*h);
u(i,n+1)=feval(f2,(i-1)*h);
u(1,i)=feval(g1,(i-1)*h);
u(n+1,i)=feval(g2,(i-1)*h);
end
iter=0;
err=tol+1;
while (err>tol)&(iter<itmax)
err=0;
for i=2:n
for j=2:n
oldu=u(i,j);
u(i,j)=(u(i+1,j)+u(i-1,j)+u(i,j+1)+u(i,j-1))/4;
res=abs(u(i,j)-oldu);
if (err<res);
err=res;
end
end
end
iter=iter+1;
end
for i=1:n+1
fprintf('
%4.2f',z(i))
for j=1:n+1
fprintf('%10.4f ',u(i,j))
end
fprintf('\n')
end
iter
Figure 3.15: The MATLAB program for the resolution of the Laplaces equation.
Using Gaussian elimination, the temperature at the interior grid point is
V1 = 166.071; V2 = 164.286; V3 = 191.071; V4 = 200.000;
V5 = 200.00; V6 = 2000; V7 = 233.929; V8 = 235.714; V9 = 208.923.
Example 3.6
Use MATLAB function Laplace with n = 9 to approximate solution of the Laplaces
equation in the square region 0 < x < and 0 < y < , subject to the boundary
conditions
U (x, 0) = 0, U (x, ) = sin x, 0 x ,
U (0, y) = 0, U (, y) = 0, 0 y .
We use The MATLAB program for the resolution of the Laplaces equation by setting
the tolerance value to 106 and the maximum number of iterations to 120 to get the result
47
X
U(x,2)=100
2
V1
V2
V3
U2,4=300
V4
V5
V6
U(0,y)=200
U4,2 =200
V7
V8
U(2,y)=200y
V9
U4,1=100
U(x,0)=300
x\y
0.00
48
0.35
0.70
1.05
1.40
1.75
2.09
0.00 0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.35 0.0000
0.0108
0.0228
0.0377
0.0570
0.0833
0.70 0.0000
0.0202
0.0429
0.0708
0.1072
1.05 0.0000
0.0273
0.0579
0.0954
1.40 0.0000
0.0310
0.0658
1.75 0.0000
0.0310
2.09 0.0000
2.79
3.14
0.0000
0.0000
0.0000
0.1196
0.1703
0.2416
0.3420
0.1566
0.2248
0.3201
0.4541
0.6428
0.1445
0.2109
0.3029
0.4313
0.6118
0.8660
0.1085
0.1643
0.2399
0.3444
0.4905
0.6957
0.9848
0.0658
0.1085
0.1643
0.2399
0.3444
0.4905
0.6957
0.9848
0.0273
0.0579
0.0954
0.1445
0.2109
0.3029
0.4313
0.6118
0.8660
2.44 0.0000
0.0202
0.0429
0.0708
0.1072
0.1566
0.2248
0.3201
0.4541
0.6428
2.79 0.0000
0.0108
0.0228
0.0377
0.0571
0.0833
0.1196
0.1703
0.2416
0.3420
3.14 0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
0.0000
iter =
2.44
35
0.8
0.6
0.4
0.2
0
4
3.5
3
3
2.5
2
1.5
1
y
1
0
0.5
0
Conclusion
Our work is interested in numerical resolution of PDEs. The finite difference method
is used. The implementation has been made using Matlab language. The result show
that the finite difference method has significant advantages to solve PDEs.
For that reason, we recommend scientists who interact with partial differential equations, especially engineers and physicians to adopter those methods.
Bibliography
[1] G. F. Carrier and C. E. Pearson, Partial Differential Equations and technique, Academic Press, New York San Francisco London, 1976
[2] http://en.wikipedia.org/wiki/Lax-Wendroff method.
[3] B. F. Gerald, Real analysis, Washington, 1984.
[4] E. Isaacson and H. B. Keller,Analysis of Numerical Methods, Wiley, New York,
2nd Edition, 1990.
[5] P. K. Kythe, P. Puri, M. R. Schaferkotter, Partial Differential Equations and Boundary value problems with mathematica, A CRC Press Company, Boca Raton London
New York Washington, D.C. 2nd Edition, 2003.
[6] P. Prasad & R. Ravindran, Partial Differential Equations, New age international(p)
limited publication Bangole, 1985.
[7] J. Rappaz & M. Picasso, Introduction `
a lanalyse numerique, Presses polytechnique
et universitaires romandes, CH-1015 Lausane, 2004.
[8] D. U. von Rosenberg, Method for the numerical solution of partial differential
eqEdited by R. Bellman, American Elsevier Publishing Company, Inc.New York,
1969.
[9] E. C.Young, Partial Differential Equations an itroduction, Allyn and Bacon inc,
Boston, 1972.