You are on page 1of 7

American Journal of Applied Mathematics

2018; 6(1): 1-7


http://www.sciencepublishinggroup.com/j/ajam
doi: 10.11648/j.ajam.20180601.11
ISSN: 2330-0043 (Print); ISSN: 2330-006X (Online)

On the Solution Procedure of Partial Differential Equation


(PDE) with the Method of Lines (MOL) Using
Crank-Nicholson Method (CNM)
Mohammad Roknujjaman1, Mohammad Asaduzzaman2, *
1
Department of Computer Science and Engineering, Northern College Bangladesh, Dhaka, Bangladesh
2
Department of Mathematics, Islamic University (IU), Kushtia, Bangladesh

Email address:
*
Corresponding author

To cite this article:


Mohammad Roknujjaman, Mohammad Asaduzzaman. On the Solution Procedure of Partial Differential Equation (PDE) with the Method of
Lines (MOL) Using Crank-Nicholson Method (CNM). American Journal of Applied Mathematics. Vol. 6, No. 1, 2018, pp. 1-7.
doi: 10.11648/j.ajam.20180601.11

Received: December 28, 2017; Accepted: January 16, 2018; Published: February 12, 2018

Abstract: In this paper we used the method of lines (MOL) as a solution procedure for solving partial differential equation
(PDE). The range of applications of the MOL has increased dramatically in the last few years; nevertheless, there is no
introductory to initiate a beginner to the method. This Paper illustrates the application of the MOL using Crank-Nicholson
method (CNM) for numerical solution of PDE together with initial condition and Dirichlet’s Boundary Condition. The
implementation of this solutions is done using Microsoft office excel worksheet or spreadsheet, Matlab programming
language. Finally, here we analysis the particular solution and numerical solution of Laplace equation obtained by MOL along
with CNM.

Keywords: Dirichlet’s Boundary Condition, Laplace Equation, MOL, PDE, CNM

solvers are readily available; see for instance [1-11].


1. Introduction The connection between partial and ordinary differential
Method of lines (MOL) is an alternative computational equation was already known to Lagrange in 1759 [12]. There
he obtained a system of ordinary differential equations
y K 2y y
procedure which involves making an approximation to the
space derivatives and reducing the problem to a system of
y K y 2y y
ordinary differential equations (ODEs) in the variable time

and then a proper initial value problem solver can be used to (1)
solve this system of ordinary differential equations. Usually y K y 2y
and one or more space variables , , … … … . , . They are
the method is used on equations involving a time variable
Lagrange observed that by modeling D’Alembert’s
solved by converting them to a system of ODEs. The part of equation
∂ u ∂ u
the equations involving the space variables is discredited,
a
∂t ∂x
giving us a system of ODEs approximating the PDE. This
system can then be integrated directly with a standard ODE
code. It might be more efficient to solve a PDE by a method with a finite number of mass points attached to a light string,
specially constructed to suit the problem, but the MOL the same equations as like (1) are found. It is also noted that
usually enables us to solve quite general and complicated Fourier in 1807 [12] motivated by the problem of heat
PDEs relatively easily and with acceptable efficiency. The conduction and he obtained the following equation
y K y 2y y , 1,2, … , N
MOL is also attractive since we can use the theoretical
knowledge from ODEs to solve PDEs, and powerful ODE (2)
2 Mohammad Roknujjaman and Mohammad Asaduzzaman: On the Solution Procedure of Partial Differential Equation
(PDE) with the Method of Lines (MOL) Using Crank-Nicholson Method (CNM)

By taking # larger and larger in (2) he obtained the heat Note that the equation (7) represents a system of ODEs.
equation This transformation of a PDE equation (5) to a system of
$% $ %
&
ODEs equation (7) is so that the solution of a system of

$ $
ODEs approximates the solution of the original PDE. Since
equation (5) is first order, it requires one IC and one BC.
using the inverse of the MOL. But the MOL as a numerical These will be as follows, which are collected from [21]:
method was first applied by Rothe in 1930 [12]. He used the u x, t = 0 = f x (8)

u x = 0, t = g x
method on the parabolic equation
u'' = R x, t u) + S x, t, u
(9)
(3)

With R > 0,0 ≤ ≤ 1,0 ≤ ≤ .. He discretised the time


Since equation (7) constitute M initial value ODEs, M
variables in 3 and approximated the equation by the
initial conditions are required and from equation (8), these
are
scheme

u = R x, t + S x, t , u , t = nh. (4)
0123 01 u ( xi , t = 0) = f ( xi ) 1 ≤ i ≤ M (10)
4

The equation (4) is the integration of the ODEs along lines Also, application of BC (9) gives for grid point i=1
u x ,t = g t ,t ≥ 0
parallel to the x-axis, and this is called a transversal scheme.
(11)
That is, longitudinal schemes lead to initial value problems,
while transversal schemes lead to boundary value problems. The solution of this ODE system is as follows which are
In this paper we established a solution procedure of PDE by collected from [16]:
u t , u t , u t , … , uB t , uB t
the help of MOL along with CNM and finally studied the
particular and numerical solution of Laplace equation by that (12)
solution procedure obtained by MOL along with CNM.
That is, an approximation to u (x, t) at the grid points i =1,
2,…, M
2. Conversion of PDE to the System of Before we go on to consider the numerical integration of
ODE the approximating ODEs, in this case equation (7), we briefly
consider further the FD approximation of equation (12),
The basic idea of the MOL is to replace the spatial which can be written as

u' ≈ + 0 ∆x
(boundary value) derivatives in the PDE with algebraic 09 09:3
∆'
approximations. Once this is done, the spatial derivatives are (13)

where, 0 ∆ denotes of order ∆ .


no longer stated explicitly in terms of the spatial independent
variables. Thus, in effect only the initial value variable,
typically time in a physical problem, remains, we have a
system of ODEs that approximate the original PDE. The 3. Laplace Equation [13-16] and Problem
challenge, then, is to formulate the approximating system of
ODEs. Once this is done, we can apply any integration
Definition
algorithm for initial value ODEs to compute an approximate Consider the PDE of the following form
numerical solution to the PDE. Thus, one of the salient
features of the MOL is the use of existing, and generally well ∆u = 0 (14)
established, numerical methods for ODEs.
To illustrate this procedure, we consider the MOL solution where the Laplacian ∆ is defend in Cartesian coordinates by
of
∂2 ∂2 ∂n
u) + vu' = 0 (5) ∆u = + + ........ +
∂x
2
∂x 2
1 2 ∂x 2
n

First we need to replace the spatial derivative u x with an This is known as Laplace's equation. It is also called a
algebraic approximation. In this case we will use a finite harmonic function. Equation (14) is Eclliptic second order
difference (FD) such as linear PDE. The initial condition is

u' ≈
09 09:3 x x, o = f x a < x < b (15)
∆'
(6)
And the Dirichlet Boundary conditions are
u a, t = c , u b, t = c , 0 ≤ t ≤ d
Then the MOL approximation of equation (5) is

= −v ,1 ≤ i ≤ M
<09 09 09:3
(16)
<) ∆'
(7)
Equation (14), (15) and (16) are called initial boundary
American Journal of Applied Mathematics 2018; 6(1): 1-7 3

condition. To compute the numerical solution of equation and [ _∆ .

equal parts with step lenth H = ∆ . we consider a


I
(14) together equation (15), (16). we divide the interval into n Substituting equations (18) and (19) into (14) yield

YΡ\YZ M \ 0
J RS TY X \
plane region defined K L , M : 0 - - 0.5 and 0 - M - RX S WS
P. 5 we will also impose the Dirichlet boundary condition
(20)

% P, M 0, % , P 0; % , 0.5 200 , % 0.5, M where [P] is an # a # tridiagonal matrix representing the


200M discretised form ofthe second derivative with respect to .
ef 1 0 … 0
d 1 2 1 0 … … 0k
Consider a two-dimensional solution shown in Figure 1 [4]

c j
c ⋱ ⋱ ⋱ j
YΡ\ c 0 … 1 2 1 j
c 0 … 0 1 eh j
c j
b i
Since all the elements of matrix [P] are zeros except the

0 and &.
tridiagonal terms; the elements of the first and the last row of

ef 2 for the Dirichlet boundary condition and ef 1 for


[P] depends on the boundary conditions at

the Neumann boundary condition. The same is true of eh .

along the M coordinate. To solve equation (20) analytically,


The next step is to solve the resulting equations analytically

we need to obtain a system of uncoupled ordinary differential

l ] by letting
equations from the coupled equations (20). To achieve this,
we define the transformed potential [Z

Y Z\ l\
YΤ\YZ (21)

And requiring that


YP\YΤ\ Yo \
Figure 1. Illustration of discretization in the -direction.
(22)
where, [o ] is a diagonal matrix and YΤ\] is the transpose of
is divided into strips by # dividing straight lines (hence the
The first step is discretization of the -variable. The region

name method of lines) parallel to the M-axis. Since we are


belonging to [P]. The transformation matrix [ Τ ] and the
[Τ]. [o ] and [Τ] are eigenvalue and eigenvector matrices

eigenvalue matrix [ o ] depend on the boundary


discretizing along , we replace the second derivative with
respect to with its finite difference equivalent. We apply the
conditionsand are given in Table 1 for various combinations
three-point central difference scheme,
of boundaries. It should be noted that the eigenvector matrix

R S TU TU:3 TU TU23 [Τ] has the following property:
RV S WS
YΤ\ YΤ\]
(17)

Where H is the spacing between discretised lines, that is,


(23)

H ∆
I
And
J
YΤ\YΤ\] YΤ\] YΤ\ YΙ\
(18)
(24)

Where, YΙ\ is an identity matrix. Substituting equation (21)


Replacing the derivative with respect to by its finite
difference equivalent equation (14) becomes
into equation (20) gives
YZ[ M 2Z[ M Z[ M \ 0
R S TU
l\
YΡ\YΤ\YU
l\
0
qS Yr\Ys
RX S WS
(19)
qtS 4S
(25)
Thus the potential Z in equation (14) can be replaced by a
Multiplying through by YΤ\ YΤ\] yields
vector of size # namely
YZ\ YZ , Z , … … … , ZJ \] u
qS
l\
Yλ \w YU 0
qtS 4S
(26)

Where,
U y U x ,y ,i 1,2, … . . , N
4 Mohammad Roknujjaman and Mohammad Asaduzzaman: On the Solution Procedure of Partial Differential Equation
(PDE) with the Method of Lines (MOL) Using Crank-Nicholson Method (CNM)

Table 1. Elements of Transformation matrix [T] and Eigen values [19-20].

Left boundary Right boundary xyz {y


2 _~• _•
| sin , YT \ 2 sin
#+1 # + 1 •• 2 #+1
Dirichlet Dirichlet

2 _ ~ − 0.5 • _ − 0.5 •
| sin , YT•J \ 2 sin
# + 0.5 # + 0.5 2# + 1
Dirichlet Neumann

2 _ − 0.5 ~ − 0.5 • _ − 0.5 •


| cos , YTJ• \ 2 sin
# + 0.5 # + 0.5 2# + 1
Neumann Dirichlet

2 _ − 0.5 ~ − 1 •
| cos ,
# + 0.5 # + 0.5 _−1 •
2 sin
1 2#
Neumann Neumann
~ > 1, YTJJ \| , ~ = 1
#

Note: where i, j = 1, 2, N and subscripts D and N are for Dirichlet and Neumann conditions respectively. This is an ordinary differential equation with solution.

l[ = ‚[ cosh ƒ[ M + „[ sinh ƒ[ M
Z (27)
where, ƒ[ = o[ /H.

4. A Particular Solution of Laplace 2-D Equation


In this section we obtained a particular solution of Laplace 2-D equation by applying MOL.
Example 1.
For the rectangular region in Figure 1, let
Z 0, M = Z &, M = Z , 0 = 0, Z , † = 100
and & = † = 1.
Find the potential at
0.0625,0.9375 , 0.125,0.875 , 0.1875,0.8125 , 0.25,0.75 , 0.3125,0.6875 , 0.375,0.625 ,
0.4375,0.5625 , 0.5,0.5 , 0.5625,0.4375 , 0.625,0.375 , 0.6875,0.3125 , 0.75,0.25 ,
0.8125,0.1875 , 0.875,0.125 , 0.9375,0.625 .

= 0 and = 1, which are already indirectly taken care of in the solution in


Solution of Example 1.
In this case, we have Dirichlet boundaries at
(27). Hence, from Table 1,

λ = 2 sin
Œ

(28)

and

T Ž = • sin
ŽŒ
• •
(29)

Let #=15 So then H = ∆ = 1/16 and


= 0.0625, 0.125, 0.1875,0.25,0.3125,0.375,0.4375,0.5,0.5625,
0.625,0.6875,0.75,0.8125,0.875,0.9375 will correspond to _ = 1, 2,3,4,5,6,7,8,9,10,11, 12,13,14,15 respectively.
American Journal of Applied Mathematics 2018; 6(1): 1-7 5

50

au'' + bu' + cu − u) = 0
45
(30)
40
subject to the initial condition u (x, 0) = f (x) and other
35
possible boundary conditions. Explaining the negative ut
30 term in (30), focusing on an arbitrary internal grid point in
one could approximate the partial derivatives at that point by
25
y

the following:
20

15 u = u i ,n

∂ u ui , n + 1 − ui , n
10

5 =
∂t k
(31)
∂ u u i + 1, n − u i − 1, n
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
x =
∂x 2h
Figure 2. Graphical Representation of the particular solutions of Laplace 2-
D Equation by the MOL for Example 4.1.
∂2u u i + 1, n − 2 u i , n + u i − 1, n
=
∂x 2 h2
5. Crank-Nicholson Algorithm [17-18]
This note provides a brief introduction to finite difference The differences in the x, direction have been centered on
methods for solving partial differential equations. We focus the point in to give ‘second order’ accuracy to the
on the case of a PDE in one state variable plus time. Suppose approximation. These expressions could then be substituted
one wishes to find the function u (x, t) satisfying the PDE into the PDE Solving the resulting equation for ui,n+1 gives
the explicit solution

k k 2k k k
ui , n +1 = ( 2 a + b ) ui +1, n + (1 + kc − 2 a ) ui , n + ( 2 a − b ) ui −1, n (32)
h 2h h h 2h

The result of the equation (32) is called an explicit finite


difference solution for u. Unfortunately the numerical R = ( x , y )/0< x <0.5 ,0< y <0.5 and
solution is unstable unless the ratio k/h2 is sufficiently small.

Nicholson algorithm, Thus the expressions for u, %V and u xx


The recommended method for most problems in the Crank- u (0, y ) = 0 ; u ( x , 0 ) = 0

are averages of what we had in (31) for times n and n+1 u ( x ,0.5 ) = 200 x and u ( 0.5, y ) = 200 y
ui , n + ui , n +1
u = using CNM and MOL.
2 Solution of Example 2.
∂u ui , n +1 − ui , n Given that,
=
∂t k
(33) ∂2u ∂2u
∂u ui +1, n − ui −1, n + ui +1, n +1 − ui −1, n +1 + =0 (34)
= ∂x2 ∂y2
∂x 4h

∂ 2 u ui +1, n − 2 ui , n + ui −1, n + ui +1, n +1 − 2 ui , n +1 − ui −1, n +1 Now we applying the CNM


=
∂x 2 2 h2
∂ 2u 1
= [u − 2ui , j + ui −1, j + ui +1, j +1 − 2ui , j +1 + ui −1, j +1 ]
∂x2 2 h2 i +1, j
6. A Numerical Solution of Laplace 2-D
Equation Where, h is the spacing between discredited lines [4]

In this section we obtained a numerical solution of Laplace a


h = ∆x =
2-D equation by applying MOL N +1
Example 2.
RS • RS •
+ = 0 with boundary
Equation (34) becomes,
RV S RX S
Solve the Laplace equation
condition,
6 Mohammad Roknujjaman and Mohammad Asaduzzaman: On the Solution Procedure of Partial Differential Equation
(PDE) with the Method of Lines (MOL) Using Crank-Nicholson Method (CNM)

∂2u( i , j ) 1
+ [ ui +1, j − 2ui , j + ui −1, j + ui +1, j +1 − 2ui , j +1 + ui −1, j +1 ] = 0
∂y2 2 h2

∂2u(i , j ) 1
= [ −ui +1, j + 2ui , j − ui −1, j − ui +1, j +1 + 2ui , j +1 − ui −1, j +1 ] (35)
∂y2 2 h2

Now using the Figure 3 which domain is divided into The boundary condition implies that,
squares of 0.125 unit size as illustrated below,
u1,0 = u 2,0 = u 3,0 = u 0,1 = u 0,2 = u 0,3 = 0

u1,4 = u4,1 = 25 , u2,4 = u4,2 = 50 and u3,4 = u4,3 = 75

for each i, j=1, 2, 3 … and so on.


Now we use the boundary condition and finite difference
method to convert PDE to ODE and then apply the ODE
solver to solve the system of ODE. Then we use Matlab code
to find the value of ODE and to find the numerical solution
of the PDE by applying the CNM.
Figure 3. Domain dividation into squares of 0.125 unit size Again, we have from CNM

∂ 2u 1
= [ui , j +1 − 2ui , j + ui , j −1 + ui +1, j +1 − 2ui +1, j + ui +1, j −1 ]
∂y 2 2h 2

∂ 2u 1
Similarly, =
[ui +1, j − 2ui , j + ui −1, j + ui +1, j +1 − 2ui , j +1 + ui −1, j +1 ]
∂x 2
2h 2
Then the CNM for the Laplace equation is as follows

1
[ ui +1, j − 2 ui , j + ui −1, j + ui +1, j +1 − 2 ui , j +1 + ui −1, j +1 + ui , j +1 − 2 ui , j
2h 2
+ ui , j −1 + ui +1, j +1 − 2 ui +1, j + ui +1, j −1 ] = 0

∴[−ui +1, j − 4ui , j + ui −1, j + 2ui +1, j +1 − ui , j +1 + ui −1, j +1 + ui , j −1 + ui +1, j −1 ] = 0

Again for i, j=1, 2, 3… and use Matlab code for solving the numerical solution of Laplace equation using CNM.

Figure 4. Graphical Representation of the numerical solution of Laplace Equation by the MOL for Example 2.
American Journal of Applied Mathematics 2018; 6(1): 1-7 7

7. Results and Discussion problem solving”, J. Aerosol Sci. 30 (Suppl. I), S247–S248
(1999).
Here we give a simple introduction on MOL and on CNM
[6] A. Erdem and S. Pamuk, “The method of lines for the
with illustrative examples. The graph of Example 1 presented numerical solution of a mathematical model for capillary
in Figure 2 represents the particular solution of Laplace formation: the role of tumor angiogenic factor in the extra-
equation and the graph of Example 2 presented in Figure 4 cellular matrix”, Appl. Math. Comput. 186, 891–897 (2007).
represents the numerical solution of Laplace equation.
[7] G. Hall and J. M. Watt, “Modern Numerical Methods for
Ordinary Differential Equations, Clarendon”, Oxford (1976).
8. Conclusion [8] S. Hamdi, W. H. Enright, Y. Ouellet and W. E. Schiesser,
The MOL is generally recognized as a comprehensive and “Method of lines solutions of the extended Boussinesq
equations”, J. Comput. Appl. Math. 183, 327–342 (2005).
powerful approach to approximate the numerical solution of
PDEs. Here we used this method in two separate steps. First [9] H. Han and Z. Huang, “The direct method of lines for the
we discretized the PDE using crank-Nicholson method to numerical solution of interface problem”, Comput. Methods
obtain a system of ordinary differential equations (ODEs). Appl. Mech. Eng. 171, 61–75 (1999).
Then we solved the system of ODEs using ODE solvers. The [10] T. Koto, “Method of lines approximations of delay differential
success of this method is explained by the availability of equations”, Comput. Math. Appl. 48, 45–59 (2004).
high-quality numerical algorithms for the solution of stiff
[11] S. Pamuk and A. Erdem, “The method of lines for the
systems of ODEs. Here we investigated MOL approach for numerical solution of a mathematical model for capillary
solving the two dimensional Elliptic equation with boundary formation: the role of endothelial cells in the capillary”, Appl.
condition. The computational results confirmed the Math. Comput. 186, 831–835 (2007).
efficiency, reliability and accuracy of this procedure and this
[12] W. E. Schiesser, “The Numerical Method of Lines”, Academic
superior performance is achieved with very little increased Press, San Diego.
computational effort. Thus, we conclude that the use of CNM
in the MOL solution for the Laplace equation and for other [13] D. J. Jones et al, “On the numerical solution of elliptic partial
partial differential equations is very effective and appropriate differential equations by the method of lines”, J. Comput.
Phys., 9, 496–527 (1972).
procedure.
[14] J. G. Ma and Z. Chen, “Application of the method of lines to
the Laplace equation”, Micro. Opt. Tech. L ett., 14 (6), 330–
Conflict of Interests 333 (1997).
The authors declare that they have no any conflict of [15] A. A. Sharaf and H. O. Bakodah,“A Good Spatial
interests. Discretization in the Method of Lines”, Applied Mathematics
and Computation” (2005).

[16] Z. A. Vlasova, “A Numerical Realization of the Method of


References Reduction to Ordinary Differential Equations”, Sibirsk. Math.
Za. 4, 475-479 (1963).
[1] I. Ayranci and N. Selçuk, “MOL solution of DOM for
transient radiative transfer in 3-D scattering media”, J. Quant. [17] W. E. Schiesser, and G. W. Griffths, “A Compendium of
Spectrosc. Radiat. Transfer 84, 409–422 (2004). Partial Differential Equation Models: Method of Lines
Analysis with Matlab”, Cambridge University Press (2009).
[2] A. G. Bratsos, “The solution of the two-dimensional sine-
Gordon equation using the method of lines”, J. Comput. Appl. [18] G. D. Smith, “Numerical Solution of Partial Differential
Math. 206, 251–277 (2007). Equations (Crank-Nicholson Methods)”, 3rd Edition, Oxford
University Press, Oxford (1985).
[3] A. G. Bratsos, “The solution of the Boussinesq equation using
the method of lines”, Comput. Methods Appl. Mech. Eng. [19] S. G. Mikhlin, and K. L. Smolitskii, “Approximate Methods
157, 33–44 (1998). for Solving Differential and Integral Equations”, Moscow
1965, pp 329-335 (1965).
[4] A. G. Bratsos and E. H. Twizell, “The solution of the sine-
Gordon equation using the method of lines”, Int. J. Comput. [20] H. O. Kreiss and J. Lorenz, “Initial-Boundary Value Problems
Math. 61, 271–292 (1996). and the Navier-Stokes Equations”, SIAM, Philadelphia
(2004).
[5] V. D. Egorov, “The mehtod of lines for condensation kinetics

You might also like