finite difference method for the resolution
DESCRIPTION
Finite difference methotdsTRANSCRIPT
-
NATIONAL UNIVERSITY OF RWANDA
FACULTY OF SCIENCES
DEPARTEMENT OF APPLIED MATHEMATICS
ACADEMIC YEAR: 2009
FINITE DIFFERENCE METHOD FOR THE RESOLUTION
OF SOME PARTIAL DIFFERENTIAL EQUATIONS:
A MATLAB APROACH.
Project submitted to obtain Bachelors degree in Applied Mathematics
Presented by: BIZIMUNGU Anaclet & NDAHIMANA RUKUNDO Janvier
Supervisor: Dr NTAGANDA Jean Marie
Huye, October 2009
-
i
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).
NDAHIMANA RUKUNDO Janvier
-
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, Dr. LYAMBABAJE Alexandre and Dr. SAFARI Bonfils.
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.
May the Almighty God bless you all.
BIZIMUNGU Anaclet NDAHIMANA RUKUNDO Janvier
-
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
2 Presentation of .finite methods.13 2.1 Grid lines...13 2.2 Finite different schemes ...14 2.3 First order partial derivative......15 2.3.1 Central partial difference formula .....15 2.3.2 Forward difference formula....15 2.3.3 Backward Difference Formula...16 2.4 First order partition derivative in two independent variables ......16 2.4.1 Central partial difference formulas in two independent variables.........16 2.4.2 Forward difference formulas in two independent variables .............18 2.4.3 Backward difference formulas in two independent variables ...........18 2.5 The second order partial derivative.......18 2.6 Partial derivative in two independent variables....18 2.6.1 Central difference formulas in two independent variables.............19
2.6.2 Forward difference schemes in two independent variables ..........................19 2.6.3 Backward difference schemes in two independent variables .......19 2.7 Some schemes that use a Finite Difference Method ........20 2.7.1 Explicit method .....20
-
v
2.7.2 Implicit method .....21 2.7.3 The Lax-Wendroff method .......25
3 Numerical solution of three forms of partial differential equations......26 3.1 Parabolic equations ......26 3.1.1 Forward difference (Explicitly scheme) ...27 3.1.2 The classical implicit method ...30 3.1.3 The Crank-Nicolson method .....33 3.2 Hyperbolic equations ...36 3.2.1 Implicit scheme .....37
3.2.2 Explicit scheme (Forward difference) ..38 3.3 Elliptic equation .......42
Conclusion.............................................................................................................................49 Bibliography..........................................................................................................................50
-
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 Reduc-
tion Strategy (EDPRS), Rwanda as a country with low natural resources, need to es-
tablish 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 mathe-
matics 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 appli-
cations 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 tech-
niques 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 can-
not 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
-
2domain 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 Basic concepts and definitions
A Partial Differential Equation (PDE) is an equation that involves an unknown function
of two or more independent variables and certain partial derivatives of the unknown
function. More precisely let U denote a function of the n 2 independent variablesx1, ..., xn. Then the relation of the form
F (x1..., xn, U, Ux1,...Uxn , Ux1x1 , ..., Uxnxn) = 0, (1.1)
Where F is a function of its arguments is a partial differential equation. The general
linear second order PDE in one dependent variable U may be written asn
i,j=1
Ai,jUxixj +n
i,=1
BiUxi + FU = G, (1.2)
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 + FU = G, (1.3)
-
1.1 Basic concepts and definitions 4
where the coefficients A,B,C,D,E, F and G are functions of x and y in some domain
of the xy-plane.
Definition 1.1
As an ordinary differential equation the highest-order derivative appearing in a PDE
is called the order of the equation. A PDE is said to be the second order if its order is
two. A PDE in function of U is said to be linear if it is at most of first degree in U. For
detail we can refer in [9].
It is impossible to obtain the general solution of equation (1.3) except in some special
case:
aUxx + bUxy + cUyy + dUx + eUy + fU = 0, (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 + FU = G, (1.5)
where A,B,C,D,E, F and G are constants such that A,B and C are not zero simul-
taneously. In particular we shall limit our discussion of second order equations to the
three prominent classical equations of Mathematical physics, namely
2U
t2
2U
x2= f (x, t) , (1.6)
U
t
2U
x2= g (x, t) , (1.7)
2U
y2+2U
x2= h (x, y) , (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 equa-
tions 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 Classification of second order equations 5
1.2 Classification of second order equations
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
)= xy yx,
must be equal to zero.
We now think of W as a function of and . At any point on , we know from
the prescribed data what the rate of change of is in each of the tangential and normal
directions, and so in any direction. Thus we can calculate W and W at each point
of since W and W are known functions of on , we can differentiate with respect
to to obtain values of W,W, ...,W,W, ...on . To determine W on we must
however use the equation (1.5), [1].
When the Jacobean J
(,
x, y
)is zero, its possible to write and by means of the
linear transformation = x+ y,
= x+ y.(1.9)
-
1.2 Classification of second order equations 6
Curves (x,y)=const.
Curves (x,y)=const.
Figure 1.1: Coordinate system.
The coefficient , , and are constant, which will be determined subject to the
condition
6= 0.Writing
U(x, y) =W (, ) ,
we have by chain rule
Ux = W + W,
Uy = W + W,
Uxx = 2W + 2W +
2W,
Uxy = W + ( + )W + W,
Uyy = 2W + 2W +
2W.
(1.10)
Substituting these values in equation (1.5) and collecting similar terms we have
aW + bW + cW + dW + eW + fW = g (, ) , (1.11)
Where
a = A2 + 2B + C2, (1.12)
-
1.2 Classification of second order equations 7
b = A +B ( ) + C, (1.13)
c = A2 +B + C2, (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 = (B2 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 B2 AC > 0, B2 AC = 0 and B2 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 The canonical form. 8
Hyperbolic type, if, B2 AC > 0
Parabolic type, if, B2 AC = 0 and
Elliptic type, if, B2 AC < 0
We see in the above classification that only the coefficients of the second order terms
matter. The quantity B2 AC is called the discriminate of the equation. In view ofthe formula (1.15) we see that the sign of the discriminant remain unaltered under the
change of variables (1.16) , (1.17) and (1.18). Thus the type of equation (1.5) is invariant
with respect to the linear transformation (1.9).For detail we can refer in [6]
1.3 The canonical form.
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 B2 AC > 0, in this case we shall show that (1.9) canbe chosen such that the coefficient a and c in (1.11) vanish while b 6= 0 we thereforeconsider the equations (1.12) and (1.13), if a = c = 0 then of necessity b 6= 0 and thusequation (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 isviolated. Therefore and cannot be zero and hence equation (1.12) and (1.13) can
be written as
A
(
)2+ 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
that
and
are roots of the quadratic equation
Am2 + 2Bm+ C = 0. (1.21)
-
1.3 The canonical form. 9
Since B2 AC > 0 equation (1.21) has two distinct real roots
m1 =B (B2 AC) 12
A,
and
m2 =B + (B2 AC) 12
A.
Let us choose
= B + (B2 + AC) 12 , = A = B (B2 + AC) 12 ,
and
= A.
Then
= 2(B2 AC) 12 > 0,and the coefficient a and c in equation (1.11) drop out. From (1.12)-(1.14) we see that
b = A +B( ) + C,
b = 2A(B2 AC) 6= 0,therefore when equation (1.5) is of hyperbolic type the transformation
=[B + (B2 + AC) 12
]x+ Ay,
=[B (B2 + AC) 12
]x+ Ay,
will reduce the equation to the form
W = D1U + E1U + F1U +G1(, ), (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 canbe treated in very similar way. If we further introduce the variables and defined by
the equations
= +
2,
= 2
,(1.23)
-
1.3 The canonical form. 10
the canonical form becomes
W W = D1U + E 1U + F 1U +G1(, ), (1.24)
where D1, E1 and F
1 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
= Bx+ Ay, = (B2 AC) 12x, (1.25)
and dividing out the result by the coefficient A(B2AC) which is different from zero.
1.3.2 Parabolic type
The PDE is parabolic type if B2AC = 0, in this case it is clear that the coefficients Aand C cannot be both zero. Suppose that A 6= 0, the case C = 0 can be treated in similarmanner. Then the quadratic equation (1.21) has only one distinct root m = B
A. If we
can choose = B, = A and let and be any number such that say = 1and = 0 then from (1.12)-(1.14) it follow, that a = A, b = 0 and c = 0. Here we have
used the fact that B2 AC = 0 thus in the parabolic case the transformation
= x,
= Bx Ay,
reduce equation (1.5) to the form
W = D2U + E2U + F2U +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 2Bdxdy + Cd2x = 0,
we conclude that in the parabolic case there is only one family of characteristic given
by
Bx Ay = const.
-
1.3 The canonical form. 11
1.3.3 Elliptic type
The PDE is elliptic type if B2 AC < 0, here it is clear that neither A nor C can bezero. Following the discussion in hyperbolic case, we see that since B2 AC < 0 thequadratic equation (1.21) has complex roots
m1 =B + i(AC B2) 12
A,
and
m2 =B i(AC B2) 12
A.
The choice
= B i(AC B2) 12 , = = A,
and
=
with
= B + i(AC B2) 12 ,would then make the coefficients a and c of equation (1.11) vanish,with
b = 2A(AC B2) > 0.
Thus under the change of variables
=[B + i(AC B2) 12
]x+ Ay, (1.27)
=[B i(AC B2) 12
]x+ Ay,
equation (1.5) would be reduce to the form
W = D3U + E3U + F3U +G3(, ), (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
W =1
4(W +W), (1.29)
-
1.3 The canonical form. 12
so that (1.28) reduce to the canonical form
W +W = D3U + E
3U + F
3U +G
3(
, ), (1.30)
where D3, E3 and F
3 are constants. After dividing through by A(AC B2). if we
substitute and from (1.27) in (1.28), we obtain the transformation (1.25), writing
and again in place of and the transformation (1.25) corresponding to the choice
= B,
= A,
= (AC B2) 12 ,and
= 0,
in (1.9) with this choice, it is easily verified from (1.11) that
a = c = (AC B2),
and b = 0. Therefore, under the change of variables
= Bx+ Ay, = (B2 AC) 12x, (1.31)
equation (1.5) can be reduced to the desired canonical form (1.14). We introduce
since B2 AC < 0 equation (1.21) has no real integral curves. This means that anequation (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 prob-
lems, 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 con-
ditions 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
Let us consider in case of a function U (x, t) of two independent variables x and t, we
partition the x-axes into interval of length h and t-axes into interval of length k. The
(x, t)-plane is divided into equal rectangles of area hk by the gild lines (see figure 2.1)
parallel to 0t, defined by
xi = ih, i = 0,1,2..., (2.1)and by the gild lines parallel to 0x defined by
tj = jk, j = 0, j = 1, j = 2.... (2.2)We will use the following notation
Up = U(xi, tj) = U (ih, jk) = Uij, i = 0, ..., n; j = 0, ...,m,
denote the value of the function U (x, t) at mesh point P (ih, jk) .
-
2.2 Finite different schemes 14
k h
P
(i,j) (i+1,j) (i-1,j)
(i,j-1)
(i,j+1) P (ih,jk)
X 0
U
Figure 2.1: Grid lines.
2.2 Finite different schemes
Definition 2.1
If U is an open in Rn and K. N we denote by Ck (u) the space of all functions on Upossessing continuous partial derivatives of order k and we set Cc (E) = 1 Ck (U) .Furthermore, for only E Rn we denote by Cc (E) the space of all C functions onRn whose support in compact and contained in E. If E = Rn, we shall usually omit itin naming function spaces thus Ck = Ck(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 (x) +h2
2!U (X) +
h3
3!U (x) + ..., (2.3)
U (x h) U (x) hU (x) + h2
2!U (X) h
3
3!U (x) + ..., (2.4)
where h is a small step around the point x.
-
2.3 First order partial derivative 15
2.3 First order partial derivative
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 Central partial difference formula
The subtraction of (2.3) and (2.4) gives:
U (x) 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(x-h)
h h
U(x)
U(x+h)
A
P
B
X
U
0
Figure 2.2: The slop of the chord AB.
2.3.2 Forward difference formula
After some minor algebraic manipulation of the relation (2.3) we get
U (x) U(x+ h) U(x)
h, (2.6)
-
2.4 First order partition derivative in two independents variables 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)
A
B
X
U
0
x x+h
h
U(x+h)
U(x)
U(x+h)-U(x)
U
t
T
Figure 2.3: Forward derivative.
2.3.3 Backward Difference Formula
From the relation (2.4) the previous consideration permit to obtain
U (x) U(x) U(x+ h)
h, (2.7)
which known as backward difference formula, because the step h is taken in the backward
sense from the point x. For geometrical interpretation see the figure (2.4)
2.4 First order partition derivative in two indepen-
dents variables
2.4.1 Central partial difference formulas in two independents
variables
Let us consider the uniform grid
rh,k = {(xi, tj), where xi = ih, yj = jk, i = 0, ..., n; j = 0, ...,m} ,
-
2.4 First order partition derivative in two independents variables 17
A
B
X
U
0
x-h x h
U(x)
U(x-h)
U(x)-U(x-h)
U
T
t
Figure 2.4: Backward derivative.
give by the figure (2.1). In this case we have the relation (2.1) and (2.2).
Using the relation (2.5) and consider that i = 0, ..., n 1; and, j = 0, ...,m we have
U
x=U((i+ 1)h.jk) U((i 1)h, jk)
h,
U
x=U ji+1 U ji1
h,
(2.8)
where U ji = U(xi, tj) similarly, we have for i = 0, ..., n; and, j = 0, ...,m 1
U
t=U(ih.(j + 1)k) U(ih, (j 1)k)
h,
U
t=U ji+1 U ji1
h.
(2.9)
The relation (2.8) and (2.9) are known as the first-order order central partial differ-
ence formula in two independent variables.
-
2.5 The second order partial derivative 18
2.4.2 Forward difference formulas in two independents vari-
ables
From the relation (2.6) the previous consideration permit to obtain
U
x=U ji+1 U ji
h,
U
t=U j+1i U ji
k,
(2.10)
which known as forward difference formulas in two independent variables. The geomet-
rical interpretation of forward difference is show in the figure (2.3).
2.4.3 Backward difference formulas in two independents vari-
ables
Using the relation (2.7) the some previous argument permit to obtain
U
x=U ji U ji1
h,
U
t=U ji U j1i
k.
(2.11)
The relation (2.11) is known as backward difference formula in two independent vari-
ables. The figure (2.3).illustrate the geometrical interpretation of backward difference.
2.5 The second order partial derivative
The addition of the relation(2.3) and (2.4) gives
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: U(x)
U(x+ h) 2U(x) + U(x h)h2
, (2.13)
which known as the second order central partial difference formula.
2.6 Partial derivative in two independent variables
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 Partial derivative in two independent variables 19
2.6.1 Central difference formulas in two independents variables
The Central difference formulas in two independent variables is characterized by the
following relations,
2U
x2=U ji+1 2U ji + U ji1
h2; i = 1, 2...n 1; j = 1, 2...m,
2U
t2=U j+1i 2U ji + U j1i
k2; j = 1, 2...m 1; i = 1, 2...n,
2U
xt=U j+1i+1 U j1i+1 U j+1i1 + U i1j1
4hk, i = 1, 2...n 1, j = 1, 2...m 1.
(2.14)
2.6.2 Forward difference schemes in two independents vari-
ables
When the step h and k are taken in the forward sense, from the relation (2.14) we will
obtain the following formulas:
2U
x2=U ji+2 2U ji+1 + U ji
h2; i = 0, 1, 2...n 2; j = 1, 2...m,
2U
t2=U j+2i 2U j+1i + U ji
k2; j = 0, 1, 2...m 2; i = 1, 2...n,
2U
xt=U j+2i+2 U ji+2 U j+2i + U ij
4hk, i = 0, 1, 2...n 2, j = 1, 2...m 2.
(2.15)
2.6.3 Backward difference schemes in two independents vari-
ables
Let us take the step h and k in the backward sense, then the relation (2.14) permit to
obtain the following formulas [5]
2U
x2=U ji 2U ji1 + U ji2
h2; i = 1, 2...n 2, j = 1, 2...m,
2U
t2=U ji 2U j1i + U j2i
h2; j = 1, 2...m 2; i = 1, 2...n,
2U
xt=U ji U j2i U ji2 + U i2j2
4hk; i = 1, 2...n 2, j = 1, 2...m 2.
(2.16)
-
2.7 Some schemes that use a Finite Difference Method 20
2.7 Some schemes that use a Finite Difference Method
2.7.1 Explicit method
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 (tn) byU(tn+1) U(tn)
hn.
Forward Euler scheme Let us consider the notation Un = U(tn). The forward Euler
scheme enables us to calculate Un+1 from Un, and it is so possible to determine succes-
sively U1, U2, U2,... from U0. Forward Euler scheme is an explicit scheme because it
is use to approximate the solution Un+1 depending on the values of Un
Un+1 = Un + hnf(Un, tn), n = 0, 1, 2..., (2.17)
where f is a function of Un and tn.
The Euler method are used to approximate the first derivative term of U [7]
Un+1 Unhn
= f(Un, tn), n = 0, 1, 2.... (2.18)
The classical explicit method
The classical explicit method enables us to approximate the solution
U j+1i = f(Uji1, U
ji , U
ji+1), i = 0, 1, 2..., j = 0, 1, 2..., (2.19)
where f is the function of U ji1, Uji , and U
ji+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 anexplicit method.
-
2.7 Some schemes that use a Finite Difference Method 21
One important approach to approximate the solution to PDE is FDMs. In order
to approximate the solution for our problem, a network of grid point is established
throughout the rectangular region
R = {(x, t) |0 x L, 0 t T} .
As show in partition R by dividing the intervals [0, L] into n equal subintervals, each of
length
h =L
n,
and the interval [0, T ] into the m equal subintervals each of the length
k =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 Uji and the
true solution is denoted by U(xi, tj).
To obtain the classical explicit difference formula we approximate each partial deriv-
ative 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 U j+1i of the
(j + 1)th time level must depend on the values, U ji1, Uji and U
j
i+1 of U at previous level
time but the implicit difference schemes cannot directly approximate U j+1i depending
-
2.7 Some schemes that use a Finite Difference Method 22
P
(i,j) (i+1,j) (i-1,j)
(i,j+1)
X 0
U
k h h
Figure 2.5: The classical explicit scheme.
on the values, U ji1, Uji and U
ji+1 of U at previous time level. The implicit difference
formulas has the following form
f(U j+1i , Uji1, U
ji , U
ji+1) = 0, i = 0, 1, 2..., j = 0, 1, 2..., (2.20)
where f designates the function of U j+1i , Uji1, U
ji , and U
ji+1.
Euler method
Backward Euler scheme This scheme can be expressed from the following relation
[7]
Un+1 Unhn
= f(Un+1, tn+1), n = 0, 1, 2.... (2.21)
The backward Euler scheme is an implicit scheme because it cannot directly approx-
imate Un+1 depending on Un, if is not trivial. It is easy to see that from (2.21) we
have
Un+1 hnf(Un+1, tn+1) = Un, n = 0, 1, 2.... (2.22)
-
2.7 Some schemes that use a Finite Difference Method 23
The classical implicit method
The classical implicit method is used to solve PDE. For this, we approximate each
partial derivative of U by the central partial difference formula, the forward difference
formula, the backward difference formula and after we substitute those derivatives in
the given PDE; and with some minor algebraic manipulation, we express the solution
U ji depending on the values Uj+1i1 , U
j+1i and U
j+1
i+1 of U at the following time level. We
obtain the following implicit difference formula.
f(U j+1i1 , Uj+1i , U
j+1i+1 ) = U
ji i = 0, 1, 2..., j = 0, 1, 2.... (2.23)
where f designates the function of U j+1i1 , Uj+1i and U
j+1i+1 .
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
jth time level. which are obtained implicitly [5]. The figure 2.6 shows the geometrical
interpretation of classical implicit backward scheme.
P
(i,j) (i+1,j) (i-1,j)
(i,j+1)
X 0
U
k h h
Figure 2.6: The classical implicit scheme.
Crank-Nicolson method
It is show that this method is indispensable in PDE resolution [5]
-
2.7 Some schemes that use a Finite Difference Method 24
To use the Crank-Nicolson method we approximate the first derivative of U by the
forward difference and the second derivative of U by the average of the centered difference
at the time steps (j+ i) and j and we substitute them in the given PDE. using algebraic
theories, the solution value at any point (i, j+1) on the (j+1)th time level is depending
on the solution value at the neighboring point on the same level and three points on the
jth time level. Since values at the (j +1)th time level are obtained implicit, the method
is called an implicit method. For geometrical interpretation see the figure (2.7)
P
(i,j) (i+1,j) (i-1,j)
(i,j+1)
X 0
U
k h h
Figure 2.7: The Crank Nicolson scheme.
This method is unconditionally stable, and sometime it can be written in matrix
form [5].
For example if we have the Crank-Nicolson expression
aU j+1i1 + bUj+1i + cU
j+1i+1 = a
U ji1 + bU ji + c
U ji+1, i = 0, 1, 2..., j = 0, 1, 2..., (2.24)
the matrix form of (2.24) can be written (2.25)
AU (j+1) = BU (j), j = 0, 1, 2..., (2.25)
where
U (j+1) =[U
(j+1)1 , U
(j+1)2 , ..., U
(j+1)n1
]Tj = 0, 1, 2...,
-
2.7 Some schemes that use a Finite Difference Method 25
A =
b c 0 0a b c
. . ....
0. . . . . . . . . 0
.... . . a b c
0 0 a b
, B =
b c 0 0a b c
. . ....
0. . . . . . . . . 0
.... . . a b c
0 0 a b
The tridiagonal matrix A is positive definite and strictly dominant. therefore A is
nonsingular and the system of equation (2.24) has a unique solution [5].
2.7.3 The Lax-Wendroff method
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:
U (x, t)
t=V (U (x, 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:
Un+ 1
2
i+ 12
Uni Uni+12
12t
=V ni+i V ni
x, (2.27)
Second step:
Un+1i Unit
=V
n+ 12
i+ 12
V n+12
i 12
x. (2.28)
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)
subject to the boundary conditions
U(0, t) = 0, 0 < t T,U(L, t) = 0, 0 < t T, (3.2)
and the initial condition
U(x, 0) = f(x), 0 < x < L. (3.3)
-
3.1 Parabolic equations 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.
X=0 X=L
A: Area
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
U j+1i U jik
= U ji+1 2U ji + U ji1
h2, (3.4)
if we set = k
h2and solve U j+1i we will obtain the explicit difference formula
U j+1i = (1 2)U ji + (U ji+1 + U ji1) i = 1, .., .n 1, J = 0, ...,m 1, (3.5)
-
3.1 Parabolic equations 28
known as the forward difference or classical explicit method. In schematic form of
forward difference method, the equation (3.5) is show in figure 2.5 the solution at every
point (i, j + 1)of the (i, j + 1)th time is expressed in terms of the solution values at the
points (i 1, j), (i, j) and (i+ 1, j) of the previous time level.The value of the initial condition
U(xi, 0) = f(xi) i = 1, ..., n
are used in the equation (3.5) to find the values of U1i for i = 1, ..., n 1. The boundaryconditions
U(0, tj) = U(L, tj) = 0 (3.6)
imply that
U j0 = Ujn = 0 j = 1, ...,m. (3.7)
Once the approximations U1i , U2i , ..., Umi can be obtained in a similar manner. If n and
m are small values, for example n = 4, m = 3 the values of
U ij i = 1, ..., n; m = 1, ...,m
can be easily found manually. But if n and m are great numbers, it will be diffi-
cult to compute the values of U ij 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 equa-
tion 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(pix), 0 x 1,U(0, t) = U(1, t) = 0, t 0,
the exact solution to this problem is
U(x, t) = epi2t sin(pit).
JARUKNoteU(x,t)=exp(-(pi)^2t)sin(pix)
not t in place of x
JARUKNote
JARUKNoteMarked set by JARUK
JARUKNoteUnmarked set by JARUK
-
3.1 Parabolic equations 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
= kh2
= 0.25 n = Lh= 10 and m = T
k= 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
U j+1i = 0, 5Uji + 0.25(U
ji+1 + U
ji1) i = 1, .., 9; j = 0, ..., 9. (3.8)
The value of initial condition
U0i = sin(pixi), i = 1, .., 10,
are used in equation (3.5) to find the value of U ji for i = 1, ..., n, using the boundary
condition
U j0 = Uj9 = 0 j = 0, ..., 10.
-
3.1 Parabolic equations 30
For i = 1, 2 and j = 0, the approximation of U are
U1i = 0, 5U0i + 0.25(U0i+1 + U0i1) i = 1, .., 9;
U11 =1
4(U00 + 2U01 + U02 ) =
1
4[sin(0.0) + 2 sin(0.1pi) + sin(0.2pi)] = 0.301455,
U12 =1
4(U01 + 2U02 + U03 ) =
1
4[sin(0.1pi) + 2 sin(0.2pi) + sin(0.3pi)] = 0.573401.
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.0000 0.000000 0.309017 0.587785 0.809017 0.951057 1.000000 0.951057 0.809017 0.587785 0.309017 0.000000
0.0025 0.000000 0.301455 0.573401 0.789219 0.927783 0.975528 0.927783 0.789219 0.573401 0.301455 0.000000
0.0050 0.000000 0.294078 0.559369 0.769905 0.905078 0.951655 0.905078 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.697263 0.506591 0.266331 0.000000
0.0175 0.000000 0.259813 0.494194 0.680200 0.799623 0.840773 0.799623 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.0250 0.000000 0.241202 0.458793 0.631475 0.742343 0.780546 0.742343 0.631475 0.458793 0.241202 0.000000
Figure 3.3: Forward difference method for example 3.1 .
3.1.2 The classical implicit method
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 obtainU j+1i U ji
k=
U j+1i+1 2U j+1i + U j+1i1h2
, (3.9)
-
3.1 Parabolic equations 31
00.2
0.40.6
0.81
00.005
0.010.015
0.020.025
0
0.2
0.4
0.6
0.8
1
Figure 3.4: A three dimensional representation of table given by the figure 3.3.
if we set = k
h2for we obtain the implicit difference formula
U j+1i1 + (1 + 2)U j+1i U j+1i+1 = U ji 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 jth 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) =[U
(j+1)1 , U
(j+1)2 , ..., U
(j+1)n1
]T,
A =
2(1 + ) 0 0 2(1 + ) . . . ...0
. . . . . . 0... 2(1 + ) 0 0 2(1 + )
.
-
3.1 Parabolic equations 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(pix), 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
h2= 0.25 n = 5 and m = 10, the approximation of U at t = 0.0025 are found in
this manner. We first replace the value of into equation (3.10) we get the simplified
difference equation
0.25U j+1i1 + (1.5)U j+1i 0.25U j+1i+1 = U ji i = 1, .., 4; j = 0, ..., 9.At the first step t = k is given by the solution of the tridiagonal system
1.5 0.25 0 00.25 1.5 0.25 00 0.25 1.5 0.250 0 0.25 1.5
U11U12U13U14
=U01U02U03U04
,the initial conditions
U(xi, 0) = cos(pixi), i = 1, ..., 4,
are used to find the value of U0i for i = 1, ..., 4 and our system becomes1.5 0.25 0 0
0.25 1.5 0.25 00 0.25 1.5 0.250 0 0.25 1.5
U11U12U13U14
=0.99998498
0.99993992
0.99986485
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 U ij for
i = 1, ..., n;
and
j = 1, ...,m
using the programming languages [4].
-
3.1 Parabolic equations 33
3.1.3 The Crank-Nicolson method
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
U j+1i U jik
=
2
[U ji+1 2U ji + U ji1
h2+U j+1i+1 2U j+1i + U j+1i1
h2i = 1, ..., n 1
], (3.12)
if we set = k
h2as before, equation (3.12) can be written as
U j+1i1 +2 (1 + 2)U j+1i U j+1i+1 = U ji1+2 (1 2)U ji +U ji+1 i = 1, ..., n1, (3.13)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 jth 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... (3.14)
where
U (j+1) =[U
(j+1)1 , U
(j+1)2 , ..., U
(j+1)n1
]T
A =
2(1 + ) 0 0 2(1 + ) . . . ...0
. . . . . . 0... 2(1 + ) 0 0 2(1 + )
,
B =
2(1 ) 0 0 2(1 ) . . . ...0
. . . . . . 0... 2(1 ) 0 0 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
-
3.1 Parabolic equations 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(pix), 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
1.25U j+1i1 + 4.5U j+1i 1.25U j+1i+1 = 1.25U ji1 + 0.5U ji + 1.25U ji+1 i = 1, ..., 4.
-
3.1 Parabolic equations 35
% save the vecot b in bb. bb=b; for j=1:m t=j*k; fprintf('% 4.2f ',t) % Compute the coefficient vector Bu. for i=2:n d(i)=lambda*u(i-1)+2*(1-lambda)*u(i)+lambda*u(i+1); end %Boundary conditions y(n+1)=c1; y(1)=c2; % Solve the tridiagonal system Au=Bu. for i=3:n ymult=a(i-1)/bb(i-1); bb(i)=bb(i)-ymult*c(i-1); d(i)=d(i)-ymult*d(i-1); end y(n)=d(n)/bb(n); for i=n-1:-1:2 y(i)=(d(i)-c(i)*y(i+1))/bb(i); end % Write the ouput. for i=1:n+1 fprintf('%10.6f ',y(i)) end fprintf('\n') u=y; bb=b; end
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, U1i is given by the solution of the tridiagonal system4.5 1.25 0 0
1.25 4.5 1.25 00 1.25 4.5 1.250 0 1.25 4.5
U11U12U13U14
=
0.5U01 + 1.25U021.25U01 0.5U02 + 1.25U031.25U02 0.5U03 + 1.25U04
1.25U03 0.5U04
=
0.894928
1.448024
1.448024
0.894928
where
U0i = sin(piih).
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
-
3.2 Hyperbolic equations 36
t \ x 0.00 0.20 0.40 0.60 0.80 1.00
0.00 0.000000 0.587785 0.951057 0.951057 0.587785 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
Figure 3.7: Crank-Nicolson method for example 3.3.
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 = 2Uxx, 0 < x < L, t > 0, (3.15)
subject to the boundary conditions
U(0, t) = 0, t > 0,
U(L, t) = 0, t > 0,(3.16)
and the initial conditions
U(x, 0) = f(x), 0 < x < L,
Ut(x, 0) = g(x), 0 < x < L.(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
-
3.2 Hyperbolic equations 37
00.2
0.40.6
0.81
00.1
0.20.3
0.40.5
0
0.2
0.4
0.6
0.8
1
t
x
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 subdividedinto 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 thetime derivative Utt(xi, tj) by the central difference formula. the result is
U j+1i 2U ji + U j1ik2
=2
2
[U j+1i+1 2U j+1i + U j+1i1
h2+U j1i+1 2U j1i + U j1i1
h2
]. (3.18)
-
3.2 Hyperbolic equations 38
Point on the string
U: displacement
0
Y
X
Figure 3.9: Vibrating string.
If we set = k
h2and rearrange the order of the terms, we obtain the following implicit
three level difference formula
2U j+1i+1 + 2(1 2)U j+1i 2U j+1i1 = (1 + 2)U j1i + 2(U j1i1 + U j1i+1 ) 4U ji ,i = 1, .., .n 1 j = 0, ...,m 1,
(3.19)
the equation (3.14) is show in figure 2.7.
The solution value at any point (i, j + 1) on the (i, j + 1)th time level is depending
on the solution values at the neighboring points on the same level, and the three points
on the (i, j 1)thtime level and also the one point on the jth time level. Since values at(i, j + 1)thtime level are obtained implicitly, the method is an implicit method.
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
U j1i 2U ji + U j1ik2
= 2
(U ji+1 2U ji + U ji1
h2
). (3.20)
-
3.2 Hyperbolic equations 39
If we set = k
h2and rearrange the order of the terms, we obtain the explicit three
level difference formula
U j+1i = 2(1 2)U ji + 2(U ji1 +U ji+1)U j1i , 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. Theexplicit 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 U j+1i on the
(j + 1)th time level, we must use entries from the jth and (j 1)th time levels. thisrequirement creates a problem at the beginning because we only know the very first
row from the initial condition U0i = f(xi). To obtain the second row corresponding to
U1i , 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).
U(xi, k) U(xi, 0) + kUt(xi, 0) + k2
2Utt(xi, 0). (3.23)
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) = 2Uxx(xi, 0) =
2f (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)(3.25)
we have
U(xi, k) f(xi) + kg(xi) + k2
22f (xi). (3.26)
-
3.2 Hyperbolic equations 40
Finally by replacing f (xi), in the last equation, by the central difference formula, we
get a difference formula for the numerical approximation in second row
U1i f(xi) + kg(xi) +k22
2h2[f(xi1) 2f(xi) + f(xi+1)] ,
U1i (1 2)f(xi) + kg(xi) +2
2[f(xi1) + f(xi+1)] ,
(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.
-
3.2 Hyperbolic equations 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(pix), 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
= k
h2= 4
0.05
0.2= 1.0,
n = 5, and m = 10. The approximation of U at t = 0.05 for i = 1, 2, 3, 4 are as follow
U j0 = Uj5 = 0, j = 0, ..., 10
and the initial conditions give
U j0 = sin(pi0.2i), i = 0, ..., 5.
From equation (3.27) we obtain
U1i =12[f(0.2(i+ 1)) + f(0.2(i 1))] + 0.05g(0.2i),
= 0.5{sin[pi0.2(i+ 1)] + sin[pi0.2(i 1)]}, i = 1, ..., 4.Hence
U(xi, 0, 05) = [0.47552826, 0.76942088, 0.769420, 0.47552826]T , i = 1, 2, 3, 4.
For t = 2k = 0.1,we get the difference equation
U2i = U1i+1 + U1i1 U0i , i = 1, 2, 3, 4
which implies that
U(xi, 0, 1) = [0.18163563, 0.29389263, 0.29389263, 0.18163563]T , i = 1, 2, 3, 4
Using the MATLAB function hyperbolic with .T = 0.5, h = 0.2, and k = 0.05 we obtain
the solution shown in table given by the figure 3.11 . A three dimensional representation
of this table is shown in figure 3.12.
-
3.3 Elliptic equation 42
t \ x 0.00 0.20 0.40 0.60 0.80 1.00
0.00 0.000000 0.587785 0.951057 0.951057 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.000000
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)
Equation (3.29) arises in the study of steady-state or time-independent solutions of
heat equations. Because these solution do not depend on time; initial conditions are
irrelevant and only boundary conditions are specified. other applications include the
static displacement U(x, y) of the stretched membrane fastened in space along the
boundary of a region; the electrostatic and gravitational potentials in certain force fields;
and in fluid mechanics for an ideal fluid. A problem of particular interest is rectangular
-
3.3 Elliptic equation 43
00.2
0.40.6
0.81
00.1
0.20.3
0.40.5-1
-0.5
0
0.5
1
tx
u
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 parti-
tioned into a grid consisting of n m rectangles with sides h and k. The mesh pointsare given by
xi = a+ ih, i = 1, .., .n,
yj = c+ jk, J = 0, ...,m.(3.30)
By using central difference approximation for the spatial derivatives, the finite difference
equation for equation (3.29) is
U ji+1 2U ji + U ji1h2
+U j+1i 2U ji + U j1i
k2= 0, i = 1, ..., n 1, j = 0, ...,m 1, (3.31)
and the boundary conditions are
U(xi, y0) = f1(xi), i = 1, .., .n 1,U(xi, ym) = f2(xi), i = 1, .., .n 1,U(x0, yj) = g3(yj), j = 1, .., .m 1,U(xn, yj) = g3(yj), j = 1, .., .m 1,
(3.32)
after it is desirable to set h = k and in this case the equation (3.31) becomes
4U ji + U j1i + U j+1i + U ji1 + U ji+1 = 0. (3.33)
-
3.3 Elliptic equation 44
Uxx+Uyy=0
f2(x)
f1(x)
g1(x)
g2(x)
X
Y
a b
c
d
0
Figure 3.13: Stead state heat flow.
The computational molecule for the equation (3.33) is shown in the figure 3.14
The equation (3.31) with the boundary conditions (3.32) form an (n 1)(m 1)(n1)(m1) linear system of equations. The coefficient matrix of the system is sparse,but is not banded in quite the same way as we have come to expect of sparse matrices.
Instead, the matrix is striped with a tridiagonal band along the main diagonal, but with
two additional bands displaced from the main diagonal by a considerable amount.
For general use, iterative techniques often represent the best approach to the solution
of such system of equations. However, if the number of equations is not too large, a direct
solution of such systems is practical. We now illustrate the solution of the Laplaces
equation when n = m = 4.
The MATLAB program for the resolution of the Laplaces equation is given by the
figure 3.15
Example 3.5
Find an approximate solution to the steady state heat flow equation
Uxx + Uyy = 0, 0 < x < 2, 0 < y < 2,
-
3.3 Elliptic equation 45
P
(i,j) h
(i,j+1) P (ih,jk)
X 0
U
(i+1,j) (i-1,j) h
k
Figure 3.14: The computational molecule for Laplace equation.
with the initial and boundary conditions
U(x, 0) = 300, U(x, 2) = 100, 0 x 2,U(0, y) = 200, U(2, y) = 200, 0 y 2,
using h = k = 0.5.
To set up the linear system, the nine interior grid point are labelled row by row from
V1 to V9 starting from the left-top corner point as shown in figure 3.16. The resulting
system is
4 1 0 1 0 0 0 0 01 4 1 0 1 0 0 0 00 1 4 0 0 1 0 0 01 0 0 4 1 0 1 0 00 1 0 1 4 1 0 1 00 0 1 0 1 4 0 0 10 0 0 1 0 0 4 1 00 0 0 0 1 0 1 4 10 0 0 0 0 1 0 1 4
V1
V2
V3
V4
V5
V6
V7
V8
V9
=
U0,3 + U1,4 = 300U2,4 = 100
U4,3 + U3,4 = 400U0,2 = 200
0
U4,2 = 200U0,4 U1,0 = 500
U2,0 = 300U3,0 + U4,1 = 400
-
3.3 Elliptic equation 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
-
3.3 Elliptic equation 47
x
2
V2 V1 V3
V7
V8 U(2,y)=200y
U(0,y)=200
2
V4
U(x,2)=100
U2,4=300
U4,2 =200
U4,1=100
V6
V9
V5
U(x,0)=300
x X
x Y
x 0
Figure 3.16: Numbering system for internal grid points.
show in table given by the figure3.17; and a three dimensional representation of this is
shown in figure 3.18.
-
3.3 Elliptic equation 48
x\y 0.00 0.35 0.70 1.05 1.40 1.75 2.09 2.44 2.79 3.14
0.00 0.0000 0.0000 0.0000 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.1196 0.1703 0.2416 0.3420
0.70 0.0000 0.0202 0.0429 0.0708 0.1072 0.1566 0.2248 0.3201 0.4541 0.6428
1.05 0.0000 0.0273 0.0579 0.0954 0.1445 0.2109 0.3029 0.4313 0.6118 0.8660
1.40 0.0000 0.0310 0.0658 0.1085 0.1643 0.2399 0.3444 0.4905 0.6957 0.9848
1.75 0.0000 0.0310 0.0658 0.1085 0.1643 0.2399 0.3444 0.4905 0.6957 0.9848
2.09 0.0000 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 =
35
Figure 3.17: Approximate solution for example 3.6.
00.5
11.5
22.5
33.5
0
1
2
3
40
0.2
0.4
0.6
0.8
1
xy
u
Figure 3.18: A three dimensional representation of figure 3.17.
-
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 equa-
tions, especially engineers and physicians to adopter those methods.
-
Bibliography
[1] G. F. Carrier and C. E. Pearson, Partial Differential Equations and technique, Aca-
demic 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,
2ndEdition, 1990.
[5] P. K. Kythe, P. Puri, M. R. Schaferkotter, Partial Differential Equations and Bound-
ary 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.
Presentation of partial differential equationsBasic concepts and definitionsClassification of second order equationsThe canonical form.Hyperbolic typeParabolic typeElliptic type
Presentation of finite methodsGrid linesFinite different schemesFirst order partial derivativeCentral partial difference formulaForward difference formulaBackward Difference Formula
First order partition derivative in two independents variablesCentral partial difference formulas in two independents variablesForward difference formulas in two independents variablesBackward difference formulas in two independents variables
The second order partial derivativePartial derivative in two independent variablesCentral difference formulas in two independents variablesForward difference schemes in two independents variablesBackward difference schemes in two independents variables
Some schemes that use a Finite Difference MethodExplicit methodImplicit methodThe Lax-Wendroff method
Numerical solution of three forms of partial differential equationsParabolic equationsForward differenceThe classical implicit methodThe Crank-Nicolson method
Hyperbolic equationsImplicit schemeExplicit scheme
Elliptic equation