You are on page 1of 39

Method of Lines, Part I: Basic Concepts

Samir Hamdi et al. (2007, Scholarpedia, 2(7:2!"#. re$ision %2&"'' (lin) to*cite this article+
C,rator: Samir Hamdi, -./I012 (H3dropo4er 5 H3dra,lics and Solid
Mechanics La6orator3, .cole Pol3techni7,e, Paris, 8rance
C,rator: 9illiam .. Schiesser, Lehi:h ;ni$ersit3 and ;ni$ersit3 of Penns3l$ania,
;S1
C,rator: -raham 9 -riffiths, School of .n:ineerin: and Mathematical Sciences,
Cit3 ;ni$ersit3, London, ;<
===================================================================================================
>he method of lines (M?L is a :eneral proced,re for the sol,tion of time
dependent partial differential equations (P@.s. 8irst 4e disc,ss the 6asic
concepts, then in Part II 4e follo4 on 4ith an eAample implementation.
Some P@. Basics
?,r ph3sical 4orld is most :enerall3 descri6ed in scientific and en:ineerin: terms
4ith respect to three=dimensional space and time 4hich 4e a66re$iate as
spacetime. P@.s pro$ide a mathematical description of ph3sical spacetime, and
the3 are therefore amon: the most 4idel3 ,sed forms of mathematics. 1s a
conse7,ence, methods for the sol,tion of P@.s, s,ch as the M?L (Schiesser,
1991, are of 6road interest in science and en:ineerin:.
1s a 6asic ill,strati$e eAample of a P@., 4e consider
2
2
x
u
D
t
u

('
4here
u dependent $aria6le (dependent on x and t
t independent $aria6le representin: time
'
x independent $aria6le representin: one dimension of three=dimensional space
D real positi$e constant, eAplained 6elo4
/ote that e7. (' has t4o independent $aria6les, x and t 4hich is the reason it is
classified as a P@. (an3 differential e7,ation 4ith more than one independent
variable is a PDE. 1 differential e7,ation 4ith onl3 one independent $aria6le is
:enerall3 termed an ordinary differential equation (ODE)B 4e 4ill consider ?@.s
later as part of the M?L.
.7. (' is termed the diffusion equation or heat equation. 9hen applied to heat
transfer, it is Fourier's second lawB the dependent $aria6le u is temperat,re and D
is the thermal diff,si$it3. 9hen e7. (' is applied to mass diff,sion, it is Fic's
second lawB u is mass concentration and D is the coefficient of diffusion or the
diffusivity.
t
u

is the partial deri$ati$e of u 4ith respect to t ( x is held constant 4hen ta)in:


this partial deri$ati$e, 4hich is 4h3 partial is ,sed to descri6e this deri$ati$e. .7.
(' is first order in t since the hi:hest order partial deri$ati$e in t is first orderB it is
second order in x since the hi:hest order partial deri$ati$e in x is second order. .7.
(' is linear or first de!ree since all of the terms are to the first po4er (note that
order and de!ree can be easily confused.
Initial and Bo,ndar3 Conditions
Before 4e consider a sol,tion to e7. (', 4e m,st specif3 some a,Ailiar3
conditions to complete the statement of the P@. pro6lem. The number of
required auxiliary conditions is determined by the highest order derivative in
each independent variable. Since eq. (1) is first order in t and second order in
x, it requires one auxiliary condition in t and to auxiliary conditions in x. >o
ha$e a complete 4ell=posed pro6lem, some additional conditions ma3 ha$e to 6e
incl,dedB for eAample, that specif3 $alid ran:es for coefficients (<reiss and
LorenC, 200D. Ho4e$er, this is a more ad$anced topic and 4ill not 6e de$eloped
f,rther here.
2
t is termed an initial value variable and therefore re7,ires one initial condition
(IC. It is an initial $al,e $aria6le since it starts at an initial $al,e, t
!
, and mo$es
for4ard o$er a finite interval f
t t t
0 or a semi"infinite interval
t t
0

4itho,t an3 additional conditions 6ein: imposed. >3picall3 in a P@. application,
the initial $al,e $aria6le is time, as in the case of e7. ('.
x is termed a boundary value variable and therefore re7,ires two boundary
conditions (BCs. It is a 6o,ndar3 $al,e $aria6le since it "aries o"er a finite
interval f
x x x
0 , a semi"infinite interval
x x
0
or a fully infinite interval
x , and at t4o different $al,es of x, conditions are imposed on u in e7.
('. >3picall3, the t4o $al,es of x correspond to 6o,ndaries of a ph3sical s3stem,
and hence the name boundary conditions#
1s eAamples of a,Ailiar3 conditions for e7. (' (there are other possi6ilities,
1n IC co,ld 6e
u(x, tE0Eu
0
(2
4here u
!
is a :i$en f,nction of x.
>4o BCs co,ld 6e
u(x=x
0
, t E u
6
(F
( )
0
,
=

=
x
t x x u
f
(D
4here u
b
is a :i$en 6o,ndar3 (constant $al,e of u for all t. 1nother common
possi6ilit3 is 4here the initial condition is :i$en as a6o$e and the 6o,ndar3
conditions are
( ) ( ) t f t x x u
0 0 0
, = =
and
( ) ( ) t f t x x u
b f
= = ,
. #iscontinuities at the
boundaries, produced for example, by differences in initial and boundary
conditions at the boundaries, can cause computational difficulties,
particularly for hyperbolic problems.
BCs can 6e of three t3pes:
F
'. If the dependent $aria6le is specified, as in BC (F, the BC is termed Dirichlet#
2. If the deri$ati$e of the dependent $aria6le is specified, as in BC (D, the BC is
termed Neumann#
F. If 6oth the dependent $aria6le and its deri$ati$e appear in the BC, it is termed a
BC of the third type or a Robin BC.
>3pes of P@. Sol,tions
.7s. (', (2, (F and (D constit,te a complete P@. pro6lem and 4e can no4
consider 4hat 4e mean 63 a sol,tion to this pro6lem. Briefl3, the sol,tion of a
P@. pro6lem is a function that defines the dependent variable as a function of the
independent variables, in this case
( ) t x u ,
. In other 4ords, e see$ a function
that hen substituted in the P#% and all of its auxiliary conditions, satisfies
simultaneously all of these equations.
>he sol,tion can 6e of t4o t3pes:
'. If the sol,tion is an act,al mathematical f,nction, it is termed an analytical
solution. 9hile anal3tical sol,tions are the !old standard for P@. sol,tions in the
sense that the3 are eAact, the3 are also :enerall3 diffic,lt to deri$e mathematicall3
for all 6,t the simplest P@. pro6lems (in m,ch the same 4a3 that sol,tions to
nonlinear al:e6raic e7,ations :enerall3 cannot 6e deri$ed mathematicall3 eAcept
for certain classes of nonlinear e7,ations.
2. If the sol,tion is in n,merical form, e.:.,
( ) t x u ,
ta6,lated n,mericall3 as a
f,nction of x and t, it is termed a numerical solution. Ideall3, the n,merical
sol,tion is simpl3 a n,merical e$al,ation of the anal3tical sol,tion. B,t since an
anal3tical sol,tion is :enerall3 ,na$aila6le for realistic P@. pro6lems in science
and en:ineerin:, the numerical solution is an approximation to the analytical
solution, and o,r eApectation is that it represents the anal3tical sol,tion 4ith :ood
acc,rac3. Ho4e$er, n,merical sol,tions can 6e comp,ted 4ith modern=da3
comp,ters for $er3 compleA pro6lems, and the3 4ill :enerall3 ha$e :ood acc,rac3
(e$en tho,:h this cannot 6e esta6lished directl3 63 comparison 4ith the anal3tical
sol,tion since the latter is ,s,all3 ,n)no4n.
D
>he foc,s of the M?L is the calculation of accurate numerical solutions.
P@. S,6script /otation
Before 4e :o on to the :eneral classes of P@.s that the M?L can handle, 4e
6riefl3 disc,ss an alternati$e notation for P@.s. Instead of 4ritin: the partial
deri$ati$es as in e7. (', 4e adopt a subscript notation that is easier to state and
6ears a closer resem6lance to the associated comp,ter codin:. 8or eAample, 4e
can 4rite e7. (' as
xx t
u D u =
("
4here, for eAample, u
t
is s,6script notation for
t
u

. In other 4ords, a partial


deri$ati$e is represented as the dependent $aria6le 4ith a s,6script that defines the
independent $aria6le. 8or a deri$ati$e that is of order n, the independent $aria6le
is repeated n times, e.:., for e7. (', u
xx
represents
2
2
x
u

.
1 -eneral P@. S3stem
;sin: the s,6script notation, 4e can no4 consider some :eneral P@.s. 8or
eAample, a :eneral P@. first order in t can 6e considered
(&
4here an o$er6ar (o$erline denotes a $ector. 8or eAample,
G
u
denotes a $ector of
n dependent $aria6les
"
i.e., a s3stem of n sim,ltaneo,s P@.s. Similarl3,

f
denotes an n $ector of
deri$ati$e f,nctions
4here T denotes a transpose (here a ro "ector is transposed to a column
"ector. /ote also that is a $ector of spatial coordinates, so that, for eAample, in
$artesian coordinates
( )
%
& y x x , ,
G
=
4hile in cylindrical coordinates
( )
%
& r x , ,
G
=
.
>h,s, e7. (& can represent P@.s in one, t4o and three spatial dimensions.
Since e7. (& is first order in t, it re7,ires one initial condition
(7
4here
G
0
u
is an n=$ector of initial condition f,nctions
>he deri$ati$e $ector

f
of e7. (& incl,des f,nctions of $ario,s spatial
deri$ati$es,


,... , ,
G G G
G
xx x u u u
, and therefore 4e cannot state a priori the re7,ired
n,m6er of BCs. 8or eAample, if the hi:hest order deri$ati$e in in all of the
deri$ati$e f,nctions is second order, then 4e re7,ire 2

n BCs for each of the


spatial independent $aria6les, e.:., 2
2
n for a 2@ P@. s3stem, 2
3
n BCs for
a F@ P@. s3stem.
9e state the :eneral BC re7,irement of e7. (& as
(!
&
4here the s,6script b denotes boundary. >he $ector of 6o,ndar3 condition
f,nctions,

b
f
has a len:th (n,m6er of f,nctions determined 63 the hi:hest order
deri$ati$e in in each P@. (in e7. (& as disc,ssed pre$io,sl3.
P@. -eometric Classification
.7s. (&, (7 and (! constit,te a :eneral P@. s3stem to 4hich the M?L can 6e
applied. Before proceedin: to the details of ho4 this mi:ht 6e done, 4e need to
disc,ss the three 6asic forms of the P@.s as classified :eometricall3. >his
!eometric classification can 6e done ri:oro,sl3 if certain mathematical forms of
the f,nctions in e7s. (&, (7 and (! are ass,med. Ho4e$er, 4e 4ill adopt a
some4hat more descripti$e (less ri:oro,s 6,t more :eneral form of these
f,nctions for the specification of the three :eometric classes.
If the deri$ati$e f,nctions in e7. (& contain only first order deri$ati$es in ' the
PDEs are classified as first order hyperbolic. 1s an eAample, the e7,ation
(#
is :enerall3 called the linear advection equationB in ph3sical applications, v is a
linear or flo4 $elocit3. 1ltho,:h e7. (# is possi6l3 the simplest P@., this
simplicit3 is decepti$e in the sense that it can 6e $er3 diffic,lt to inte:rate
n,mericall3 since it propagates discontinuities a distinctive feature of first order
hyperbolic !D"s.
.7. (# is termed a conservation la# since it eApresses conser$ation of mass'
ener!y or momentum ,nder the conditions for 4hich it is deri$ed, i.e., the
assumptions on which the equation is based. Conser$ation la4s are a 6edroc) of
P@. mathematical models in science and en:ineerin:, and an eAtensi$e literat,re
pertainin: to their sol,tion, 6oth anal3tical and n,merical, has e$ol$ed o$er man3
3ears.
1n eAample of a first order hyperbolic system (,sin: the notation v u u u
2 '
,
is
7
('0
(''
.7s. ('0 and ('' constit,te a s3stem of two linear' constant coefficient' first
order hyperbolic PDEs.
@ifferentiation and al:e6raic s,6stit,tion can occasionall3 6e ,sed to eliminate
some dependent $aria6les in s3stems of P@.s. 8or eAample, if e7. ('0 is
differentiated 4ith respect to t and e7. ('' is differentiated 4ith respect to x
4e can then eliminate the miAed partial deri$ati$e 6et4een these t4o e7,ations
(ass,min: v
xt
in the first e7,ation e7,als v
tx
in the second e7,ation to o6tain
('2
.7. ('2 is the second order hyperbolic wave equation.
If the deri$ati$e f,nctions in e7. (& contain only second order deri$ati$es in '
the PDEs are classified as parabolic. .7. (' is an eAample of a para6olic P@..
8inall3, if a P@. contains no derivatives in t(e.:., the LHS of e7. (& is Cero it is
classified as elliptic. 1s an eAample,
('F
is (aplace's equation 4here x and y are spatial independent $aria6les in Cartesian
coordinates. /ote that 4ith no deri$ati$es in t, elliptic PDEs require no ICs, i.e.,
the3 are entirel3 6o,ndar3 $al,e P@.s.
P@.s 4ith mixed !eometric characteristics are possi6le, and in fact, are 7,ite
common in applications. 8or eAample, the P@.
('D
!
is hyperbolic"parabolic. Since it fre7,entl3 models con$ection (h3per6olic
thro,:h the term u
x
and diff,sion (para6olic thro,:h the term u
xx
, it is :enerall3
termed a convection$diffusion equation. If additionall3, it incl,des a f,nction of
the dependent $aria6le u s,ch as
('"
then it mi:ht 6e termed a convection$diffusion$reaction equation since f(u
t3picall3 models the rate of a chemical reaction. If the f,nction depends onl3 the
independent $aria6les, i.e.,
('&
the e7,ation co,ld 6e la6eled an inhomo!eneous PDE.
>his disc,ssion clearl3 indicates that P@. pro6lems come in an infinite $ariet3,
dependin:, for eAample, on linearit3, t3pes of coefficients (constant, $aria6le,
coordinate s3stem, :eometric classification (h3per6olic, elliptic, para6olic,
n,m6er of dependent $aria6les (n,m6er of sim,ltaneo,s P@.s, n,m6er of
independent $aria6les (n,m6er of dimensions, t3pe of BCs, smoothness of the IC,
etc., so it mi:ht seem impossi6le to form,late n,merical proced,res 4ith an3
:eneralit3 that can address a relati$el3 6road spectr,m of P@.s. B,t in fact, the
M?L pro$ides a s,rprisin: de:ree of :eneralit3, altho,:h the s,ccess in appl3in:
it to a ne4 P@. pro6lem depends to some eAtent on the eAperience and
in$enti$eness of the anal3st, i.e., M?L is not a sin:le, strai:htfor4ard, clearl3
defined approach to P@. pro6lems, 6,t rather, is a :eneral concept (or
philosoph3 that re7,ires specification of details for each ne4 P@. pro6lem. 9e
no4 proceed to ill,strate the form,lation of a M?L n,merical al:orithm 4ith the
ca$eat that this 4ill not 6e a :eneral disc,ssion of M?L as it mi:ht 6e applied to
an3 concei$a6le P@. pro6lem.
.lements of the M?L
>he 6asic idea of the M?L is to replace the spatial (boundary value) derivatives
in the PDE with al!ebraic approximations. ?nce this is done, the spatial
deri$ati$es are no lon:er stated eAplicitl3 in terms of the spatial independent
#
$aria6les. >h,s, in effect only the initial value variable' typically time in a
physical problem' remains. In other 4ords, 4ith onl3 one remainin: independent
$aria6le, 4e ha$e a system of ODEs that approAimate the ori:inal P@.. %he
challen!e' then' is to formulate the approximatin! system of ODEs. ?nce this is
done, 4e can appl3 an3 inte:ration al:orithm for initial $al,e ?@.s to comp,te an
approAimate n,merical sol,tion to the P@.. >h,s, one of the salient feat,res of the
M?L is the ,se of existin!' and !enerally well established' numerical methods for
ODEs.
>o ill,strate this proced,re, 4e consider the M?L sol,tion of e7. (#. 8irst 4e
need to replace the spatial deri$ati$e u
x
4ith an al:e6raic approAimation. In this
case 4e 4ill ,se a finite difference (FD) s,ch as
('7
4here i is an index desi!natin! a position alon! a !rid in x and is the spacin!
in x alon! the !rid, ass,med constant for the time 6ein:. >h,s, for the left end
$al,e of x, iE', and for the ri:ht end $al,e of x, iE%, i.e., the :rid in x has %
points. >hen the M?L approAimation of e7. (# is
('!
/ote that e7. ('! is 4ritten as an ?@. since there is no4 only one independent
variable, t. /ote also that e7. ('! represents a s3stem of % ?@.s.
>his transformation of a P@., e7. (#, to a s3stem of ?@.s, e7s. ('!, ill,strates
the essence of the M?L, namel3, the replacement of the spatial deri$ati$es, in this
case u
x
, so that the sol,tion of a s3stem of ?@.s approAimates the sol,tion of the
ori:inal P@.. >hen, to comp,te the sol,tion of the P@., 4e comp,te a sol,tion to
the approAimatin: s3stem of ?@.s. B,t 6efore considerin: this inte:ration in t,
4e ha$e to complete the specification of the P@. pro6lem. Since e7. (# is first
order in t and first order in x, it re7,ires one IC and one BC. >hese 4ill 6e ta)en as
('#
(20
'0
Since e7s. ('! constit,te % initial $al,e ?@.s, % initial conditions are re7,ired
and from e7. ('#, these are
(2'
1lso, application of BC (20 :i$es for :rid point
(22
.7s. ('!, (2' and (22 no4 constit,te the complete M?L approAimation of e7.
(# s,6Hect to e7s. ('# and (20. >he sol,tion of this ?@. s3stem :i$es the %
f,nctions
(2F
that is, an approAimation to u(x, t at the :rid points iE& ' (%.
Before 4e :o on to consider the n,merical inte:ration of the approAimatin: ?@.s,
in this case e7s. ('!, 4e 6riefl3 consider f,rther the 8@ approAimation of e7. ('7,
4hich can 6e 4ritten as
(2D
4here ?( denotes of order , that is, the truncation error (from a tr,ncated
>a3lor series of the approAimation of e7. ('! is proportional to ("aries
linearly ith B th,s e7. (2D is also termed a first order 8@ (since is to
the first po4er in the order or tr,ncation error term.
/ote that the n,merator of e7. ('7, u
i
& u
i$&
, is a difference in t4o $al,es of u.
1lso, the denominator remains finite (non'ero. Hence the name finite
difference (and it is an approAimation 6eca,se of the tr,ncated >a3lor series, so a
more complete description is first order finite difference approAimation. In fact,
in the limit the approAimation of e7. ('7 6ecomes exactly the derivative.
Ho4e$er, in a practical comp,ted=6ased calc,lation, remains finite, so e7. ('7
remains an approAimation.
''
1lso, e7. (# t3picall3 descri6es the flo4 of a ph3sical 7,antit3 s,ch as
concentration of a chemical species or temperat,re, represented 63 u, from left to
ri:ht 4ith respect to x 4ith $elocit3 v. >hen, ,sin: the 8@ approAimation of e7.
(2D at i in$ol$es u
i
and u
i$&
. In a flo4in: s3stem, u
i$&
is to the left (in x of u
i
or is
upstream or upwind of u
i
(to ,se a na,tical analo:3. >h,s, e7. (2D is termed a
first order up#ind )D approximation. -enerall3, for stron:l3 con$ecti$e s3stems
s,ch as modeled 63 e7. (#, some form of ,p4indin: is re7,ired in the n,merical
sol,tion of the descripti$e P@.sB 4e 4ill loo) at this re7,irement f,rther in the
s,6se7,ent disc,ssion.
?@. Inte:ration 4ithin the M?L
9e no4 consider 6riefl3 the n,merical inte:ration of the % ?@.s of e7s. ('!. If
the deri$ati$e
dt
du
i
is approAimated 63 a first order 8@
(2"
4here n is an indeA for the $aria6le t (t mo$es for4ard in steps denoted or indeAed
63 n, then a 8@ remains an approAimation to the deri$ati$e of e7. ('! is
or sol$in: for
' + n
i
u ,
(2&
.7. (2& has the important characteristic that it :i$es
' + n
i
u explicitly, that is, 4e
can sol$e for the sol,tion at the ad$anced point in t, nI', from the sol,tion at the
6ase point n. In other 4ords, eAplicit n,merical inte:ration of e7s. ('! is 63 the
forward FD of e7. (2", and this proced,re is :enerall3 termed the for#ard "uler
method 4hich is the most 6asic form of ?@. inte:ration.
'2
9hile the eAplicit form of e7. (2& is comp,tationall3 con$enient, it has a possi6le
limitation. If the time step

t is above a critical value' the calculation becomes


unstable, 4hich is manifest 63 s,ccessi$e chan:es in the dependent $aria6le,
n
i
n
i
u u u =
+'
, 6ecomin: lar:er and e$ent,all3 ,n6o,nded as the calc,lation
mo$es for4ard in t (for increasin: n. In fact, for the sol,tion of e7. (# 63 the
method of e7. (2& to remain sta6le, the dimensionless :ro,p ( x t v * , 4hich is
called the Courant$)riedric*s$+e#y or C)+ number, m,st remain 6elo4 a
critical $al,e, in this case, ,nit3. /ote that this stability limit places an ,pper limit
on

t for a :i$en v and


x
B if one attempts to increase the acc,rac3 of e7. (2& 63
,sin: a smaller

x (lar:er n,m6er of :rid points in x 63 increasin: %, a smaller


$al,e of

t is re7,ired to )eep the C8L n,m6er 6elo4 its critical $al,e. >h,s,
there is a conflicting requirement of improving accuracy #hile maintaining
stability.
>he 4a3 to circ,m$ent the sta6ilit3 limit of the eAplicit .,ler method as
implemented $ia the for4ard 8@ of e7. (2" is to ,se a bac*#ard )D for the
deri$ati$e in t
(27
so that the 8@ approAimation of e7s. ('! 6ecomes
or after rearran:ement (4ith ( x t v * Ea
(2!
/ote that 4e cannot no4 sol$e e7. (2! eAplicitl3 for the sol,tion at the ad$anced
point,
n
i
u , in terms of the sol,tion at the 6ase point
' n
i
u . 2ather, e7. (2! is
implicit in
n
i
u 6eca,se
n
i
u
'
is also ,n)no4nB that is, 4e m,st sol$e e7. (2!
'F
4ritten for each :rid point iE& ' (% as a sim,ltaneo,s s3stem of bidiagonal
equations (6idia:onal 6eca,se each of e7s. (2! has t4o ,n)no4ns so that
simultaneous solution of the full set of approAimatin: al:e6raic e7,ations is
re7,ired to o6tain the complete n,merical sol,tion
n
)
n n
u u u
2 '
, . >h,s, the
sol,tion of e7s. (2! is termed the implicit "uler method.
9e co,ld then nat,rall3 as) 4h3 ,se e7s. (2! 4hen e7. (2& is so m,ch easier to
,se (eAplicit calc,lation of the sol,tion at the neAt step in t of e7. (2& $s. the
implicit calc,lation of e7s. (2!. >he ans4er is that the implicit calc,lation of e7s.
(2! is often 4orth4hile 6eca,se the implicit Euler method has no stability limit
(is unconditionally stable in comparison 4ith the eAplicit method 4ith the sta6ilit3
limit stated in terms of the C8L condition. Ho4e$er, there is a price to pa3 for the
impro$ed sta6ilit3 of the implicit .,ler method, that is, 4e m,st sol$e a system of
simultaneous al!ebraic equationsB e7s. (2! is an eAample. 8,rthermore, if the
ori:inal ?@. s3stem approAimatin: the P@. is nonlinear, 4e ha$e to sol$e a
system of nonlinear al!ebraic equations (e7s. (2! are linear, so the sol,tion is
m,ch easier. >he s3stem of nonlinear e7,ations is t3picall3 sol$ed 63 a variant of
*ewton's method 4hich can 6ecome $er3 demandin: comp,tationall3 if the
n,m6er of ?@.s is lar:e (d,e to the ,se of a lar:e n,m6er of spatial :rid points in
the M?L approAimation of the P@., especiall3 4hen 4e attempt the sol,tion of
t4o dimensional (2@ and three dimensional (F@ P@.s. If 3o, ha$e had some
eAperience 4ith /e4tonJs method, 3o, ma3 appreciate that the ,acobian matrix
of the nonlinear al:e6raic s3stem can become very lar!e and sparse as the number
of spatial !rid points increases.
1dditionall3, altho,:h there is no limit for
t
4ith re:ard to sta6ilit3 for the
implicit method, there is a limit with re!ard to accuracy. In fact, the first order
,p4ind approAimation of u
x
in e7. (#, e7. (2D, and the first order approAimation
of u
t
in e7. (#, e7. (2" or (27, ta)en to:ether limit the acc,rac3 of the res,ltin:
8@ approAimation of e7 (#. ?ne 4a3 aro,nd this acc,rac3 limitation is to ,se
hi!her order FD approximations for the deri$ati$es in e7. (#.
8or eAample, if 4e consider the second order approAimation for u
x
at i
'D
(2#
s,6stit,tion in e7. (# :i$es the M?L approAimation of e7. (#
(F0
9e co,ld then reason that if the inte:ration in t is performed 63 the eAplicit .,ler
method, i.e., 4e ,se the approAimation of e7. (2" for
dt
du
u
i
t
= , the res,ltin:
n,merical sol,tion sho,ld 6e more acc,rate than the sol,tion from e7. (2&. In
fact, the M?L approAimation 6ased on this idea
(F'
is unconditionally unstableB this concl,sion can 6e demonstrated 63 a von
*eumann stability analysis that 4e 4ill not co$er here. >his s,rprisin: res,lt
demonstrates that replacing the derivatives in !D"s #ith higher order
approximations does not necessarily guarantee more accurate solutions or even
stable solutions.
/,merical @iff,sion and ?scillation
.$en if the implicit .,ler method is ,sed for the inte:ration in t of e7s. (F0 to
achie$e sta6ilit3 (or a more sophisticated eAplicit inte:rator in t is ,sed that
a,tomaticall3 adH,sts
t
to achie$e a prescri6ed acc,rac3, 4e 4o,ld find the
sol,tion oscillates ,nrealisticall3. >his n,merical distortion is one of t4o :enerall3
o6ser$ed forms of n,merical error. >he other n,merical distortion is diffusion
4hich 4o,ld 6e manifest in the sol,tion from e7. (2&. Briefl3, the sol,tion 4o,ld
eAhi6it eAcessi$e smoothin: or ro,ndin: at points in x 4here the sol,tion chan:es
rapidl3.
It sho,ld 6e noted that n,merical diff,sion prod,ced 63 a first order
approximation (e.:., of u
x
in e7. (# is to 6e eApected d,e to se$ere tr,ncation of
the >a3lor series (6e3ond the first or linear term, and that the prod,ction of
'"
n,merical oscillations 63 hi:her order approAimations is predicted 63 the
+odunov order barrier theorem ((esselin), *!!1. >o 6riefl3 eAplain, the order
6arrier is first order and an3 linear approAimation, incl,din: 8@s, a6o$e first order
4ill not 6e monotonicit3 preser$in: (i.e. 4ill introd,ce oscillations.
.7. (# is an eAample of a diffic,lt 2iemann pro6lem ((esselin), *!!1 if IC e7.
('# is discontin,o,sB for eAample, u(x,tE0Eh(x 4here h(xis the ,eaviside unit
step function. >he (eAact anal3tical sol,tion is the initial condition f,nction f(xof
e7. ('# mo$in: left to ri:ht 4ith $elocit3 v (from e7. (# and 4itho,t distortion,
i.e., u(x, tEf(x=vtB ho4e$er, the n,merical sol,tion 4ill oscillate if u
x
in e7. (# is
replaced 4ith a linear approAimation of second or hi:her order.
9e sho,ld also mention one point of terminolo:3 for 8@ approAimations. >he
2HS of e7. (2# is an eAample of a centered approximation since the t4o points at
iI'and i='are centered aro,nd the point i. .7. (2D is an eAample of a noncentered'
one"sided or upwind approximation since the points i and i ='are not centered 4ith
respect to i. 1nother possi6ilit3 4o,ld 6e to ,se the points i and iI' in 4hich case
the approAimation of u
x
4o,ld 6e downwind (for vK0. 1ltho,:h this mi:ht seem
li)e a lo:ical alternati$e to e7. ('7 for approAimatin: e7. (# at point i, the
res,ltin: M?L s3stem of ?@.s is act,all3 ,nsta6le. Ph3sicall3, for a con$ecti$e
s3stem modeled 63 e7. (#, 4e 4o,ld 6e ,sin: information that is do4n4ind of
the point of interest (point i and th,s ,na$aila6le in a s3stem flo4in: 4ith
positi$e $elocit3 v. If v is ne:ati$e, then ,sin: points i and iI' 4o,ld 6e
,p4indin: (and th,s sta6le. >his ill,strates the concept that the direction of flo#
can be a *ey consideration in forming the )D approximation of a -convective or
hyperbolic. !D".
8inall3, to concl,de the disc,ssion of first order h3per6olic P@.s s,ch as e7. (#,
since the -od,no$ theorem indicates that 8@ approAimations a6o$e first order
4ill prod,ce n,merical oscillations in the sol,tion, the 7,estion remains if there
are approAimations a6o$e first order that are nonoscillator3. >o ans4er this
7,estion 4e note first that the +odunov theorem applies to linear approximationsB
for eAample, e7. (2# is a linear approAimation since u on the 2HS is to the first
po4er. If, ho4e$er, 4e consider nonlinear approAimations for u
x
, 4e can in fact
de$elop approAimations that are nonoscillator3. >he details of s,ch nonlinear
approAimations are 6e3ond the scope of this disc,ssion, so 4e 4ill merel3
'&
mention that the3 are termed hi!h resolution methods 4hich see) a total variation
diminishin! (%-D) solution. S,ch methods, 4hich incl,de fl,A limiter (9esselin:,
200' and 4ei:hted essentiall3 nonoscillator3 (9./? (Sh,, '##! methods, see)
to a$oid non=real oscillations 4hen shoc)s or discontin,ities occ,r in the sol,tion.
So far 4e ha$e considered onl3 the M?L sol,tion of first order P@.s, e.:., e7. (#.
9e concl,de this disc,ssion of the M?L 63 considerin: a second order P@., the
para6olic e7. ('. >o 6e:in, 4e need an approAimation for the second deri$ati$e
u
xx
. 1 commonl3 ,sed second order' central approximation is (a:ain, deri$ed from
the >a3lor series, so the term ?(

x
2
represents the tr,ncation error
(F2
S,6stit,tin: e7. (F2 into e7. (' :i$es a s3stem of approAimatin: ?@.s
(FF
.7s. (FF are then inte:rated s,6Hect to IC (2 and BCs (F and (D. >his inte:ration
in t can 6e 63 the eAplicit .,ler method, the implicit .,ler method, or an3 other
hi:her order inte:rator for initial $al,e ?@.s. -enerall3 sta6ilit3 is not as m,ch of
a concern as 4ith the pre$io,s h3per6olic P@.s (a characteristic of para6olic
P@.s 4hich tend to smooth sol,tions rather than h3per6olic P@.s 4hich tend to
propa:ate nonsmooth conditions. Ho4e$er, sta6ilit3 constraints do eAist for
eAplicit methods. 8or eAample, for the eAplicit .,ler method 4ith a step

t in t,
the sta6ilit3 constraint is
2
* x t D Lconstant (so that as
x
is red,ced to achie$e
6etter spatial acc,rac3 in x,

t m,st also 6e red,ced to maintain sta6ilit3.


Before proceedin: 4ith the inte:ration of e7s. (FF, 4e m,st incl,de BCs (F and
(D. >he @irichlet BC at xEx
0
, e7. (F, is merel3
(FD
and therefore the ?@. of e7s. (FF for is not re7,ired and the ?@. for
6ecomes
'7
(F"
@ifferential 1l:e6raic .7,ations
.7. (FD is al!ebraic, and therefore in com6ination 4ith the ?@.s of e7s. (FF, 4e
ha$e a differential al!ebraic (D.E) system.
1t , 4e ha$e e7s. (FF
(F&
/ote that u
%
I'is o,tside the :rid in x, i.e., %I' is a fictitious point. B,t 4e m,st
assi:n a $al,e to u
%
I' if e7. (F& is to 6e inte:rated. Since this re7,irement occ,rs
at the 6o,ndar3 point , 4e o6tain this $al,e 63 approAimatin: BC (D ,sin:
the centered 8@ approAimation of e7. (2#
or
(F7
9e can add e7. (F7 as an al!ebraic equation to our system of equations, i.e.,
contin,e to ,se the @1. format, or 4e can s,6stit,te u
%
I' from e7. (F7 into the
e7. (F&
(F!
and arri$e at an ?@. s3stem (e7s. (FF for iEF,M,%=', e7. (F" for iE2and e7.
(F! for iE%. Both approaches, either an ?@. s3stem or a @1. s3stem, ha$e
6een ,sed in M?L st,dies. .ither 4a3, 4e no4 ha$e a complete form,lation of the
M?L ?@. or @1. s3stem, incl,din: the BCs at iE', % in e7s. (FF. >he
inte:ration of these e7,ations then :i$es the n,merical sol,tion u
'
(t, u
2
(t,Mu
M
(t.
>he precedin: disc,ssion is 6ased on a relati$el3 6asic @1. s3stem, 6,t it
indicates that inte:rators desi:ned for @1. s3stems can pla3 an important role in
M?L anal3sis.
If the implicit .,ler method is applied to e7s. (FF, 4e ha$e
'!
or (4ith
2
* x t D =
4hich is a tridia!onal s3stem of al:e6raic e7,ations (three ,n)no4ns in each
e7,ation. Since s,ch banded s3stems (the nonCero elements are 6anded aro,nd
the main dia:onal are common in the n,merical sol,tion of P@. s3stems, special
al:orithms ha$e 6een de$eloped to ta)e ad$anta:e of the 6anded str,ct,re,
t3picall3 63 not storin: and ,sin: the Cero elements o,tside the 6and. >hese
special al:orithms that ta)e ad$anta:e of the structure of the problem equations
can res,lt in maHor sa$in:s in comp,tation time. In the case of tridia:onal
e7,ations, the special al:orithm is :enerall3 called %homas' method. If the
coefficient matriA of the al:e6raic s3stem does not ha$e a 4ell defined str,ct,re,
s,ch as 6idia:onal or tridia:onal, 6,t consists of mostl3 Ceros 4ith a relati$el3
small n,m6er of nonCero elements, 4hich is often the case in the n,merical
sol,tion of P@.s, the coefficient matriA is said to 6e sparseB special al:orithms
and associated soft4are for sparse s3stems ha$e 6een de$eloped that can res,lt in
$er3 s,6stantial sa$in:s in the stora:e and n,merical manip,lation of sparse
matrices.
-enerall3, 4hen appl3in: the M?L, inte:ration of the approAimatin: ?@.*@1.s
(e.:., e7s. (2" and (FF is accomplished 63 ,sin: library routines for initial $al,e
?@.*@1.s. In other 4ords, the eAplicit pro:rammin: of the ?@.*@1.
inte:ration (s,ch as the eAplicit or implicit .,ler method is a$oidedB rather, an
esta6lished inte:rator is ,sed. >his has the ad$anta:e that: (' the detailed
pro:rammin: of the inte:ration can 6e a$oided, partic,larl3 the linear al:e6ra
(sol,tion of sim,ltaneo,s e7,ations re7,ired 63 an implicit inte:rator, so that the
M?L anal3sis is s,6stantiall3 simplified, and (2 li6rar3 ro,tines (,s,all3 4ritten
63 eAperts incl,de feat,res that ma)e these ro,tines especiall3 effecti$e (ro6,st
and efficient s,ch as automatic inte!ration step si&e ad/ustment and the ,se of
hi!her order inte!ration methods (6e3ond the first order acc,rac3 of the .,ler
methodsB also, :enerall3 the3 ha$e 6een thoro,:hl3 tested. >h,s, the ,se of
7,alit3 ?@.*@1. li6rar3 ro,tines is ,s,all3 an essential part of M?L anal3sis.
9e therefore list at the end of this article some p,6lic domain so,rces of s,ch
li6rar3 ro,tines.
Since the M?L essentiall3 replaces the pro6lem P@.s 4ith s3stems of
approAimatin: ?@.s, the addition of other ?@.s is easil3 accomplishedB this
mi:ht occ,r, for eAample, if the BCs of a P@. are stated as ?@.s. >h,s, a miAed
model consistin: of s3stems of P@.s and ?@.s is readil3 accommodated. 8,rther,
'#
this idea can easil3 6e eAtended to s3stems of ?@.*@1.*P@.s. In other 4ords,
the M?L is a $er3 fleAi6le proced,re for $ario,s com6inations of al:e6raic and
differential e7,ations (and this fleAi6ilit3 :enerall3 is not a$aila6le 4ith other
li6rar3 soft4are for P@.s.
Hi:her @imensions and @ifferent Coordinate S3stems
>o concl,de this disc,ssion of the M?L sol,tion of P@.s, 4e co$er t4o
additional points. 8irst, 4e ha$e considered P@.s in onl3 Cartesian coordinates,
and in fact, H,st one Cartesian coordinate, . B,t M?L anal3sis can in principle 6e
carried o,t in an3 coordinate s3stem. >h,s, e7. (' can 6e :eneraliCed to
(F#
4here
2
is the coordinate independent +aplacian operator 4hich can then 6e
eApressed in terms of a partic,lar coordinate s3stem. 8or eAample, in c3lindrical
coordinates e7. (F# is
(D0
and in spherical coordinates e7. (F# is
(D'
>he challen:e then in appl3in: the M?L to P@.s s,ch as e7s. (D0 and (D' is the
al:e6raic approAimation of the 2HS ( u
2
,sin: for eAample, 8@s, finite
elements or finite volumesB all of these approAimations ha$e 6een ,sed in M?L
anal3sis, as 4ell as +alerin, least squares, spectral and other methods. 1
partic,larl3 demandin: step is re!ulari&ation of sin!ularities s,ch as at (note
the n,m6er of di$isions 63 in the 2HS of e7s. (D0 and (D' and at
2 * , 0 =

(note the di$isions 63
( ) sin
in e7. (D'. >h,s the application of the M?L
t3picall3 re7,ires anal3sis 6ased on the eAperience and creati$it3 of the anal3st
(i.e., it is :enerall3 not a mechanical proced,re from 6e:innin: to end.
>he complexity of the n,merical sol,tion of hi:her dimensional P@.s in $ario,s
coordinate s3stems prompts the 7,estion of 4h3 a partic,lar coordinate s3stem
4o,ld 6e selected o$er others. >he mathematical ans4er is that the H,dicio,s
20
choice of a coordinate s3stem facilitates the implementation of the 0$s in the
numerical solution.
>he ans4er 6ased on ph3sical considerations is that the coordinate system is
selected to reflect the !eometry of the problem system. 8or eAample, if the ph3sical
s3stem has the shape of a c3linder, c3lindrical coordinates 4o,ld 6e ,sed. >his
choice then facilitates the implementation of the BC at the eAterior s,rface of the
ph3sical s3stem (eAterior s,rface of the c3linder. Ho4e$er, this can also lead to
complications s,ch as the sin:,larities in e7. (D0 (d,e to the $aria6le '*r
and '*r
2
coefficients. >he resol,tion of these complications is :enerall3 4orth the
effort rather than the ,se of a coordinate s3stem that does not nat,rall3 conform to
the :eometr3 of the ph3sical s3stem. If the ph3sical s3stem is not shaped in
accordance 4ith a partic,lar coordinate s3stem, i.e., has an irre!ular !eometry,
then an approAimation to the ph3sical :eometr3 is ,sed, :enerall3 termed body
fitted coordinates.
1s a concl,din: point, 4e mi:ht consider the ori:in of the name method of lines.
If 4e consider e7s. (FF, inte:ration of this ?@. s3stem prod,ces the sol,tion
u
2
(t, u
F
(t,Mu
M
(t (note u
'
(tEu
6
, a constant, from BC (F. 9e co,ld then plot
these f,nctions in an x=u(x,t plane as a $ertical line at each x(iE2,F,M% 4ith the
hei:ht of each line e7,al to u(x
i
,t. In other 4ords, the plot of the sol,tion 4o,ld
6e a set of $ertical parallel lines s,::estin: the name method of lines (Schiesser,
'##'.
Method of Lines, Part II: .Aample Implementation
In the main article: %he )ethod of (ines' Part 12 0asic $oncepts, 4e disc,ssed
some of the 6asic ideas 6ehind the method of lines (M?L. 9e no4 re$isit the
P#% pro6lem of e7s. (' to (D to ill,strate the details of constr,ctin: a M?L
code and to disc,ss the n,merical and :raphical o,tp,t from the code.
>he specific initial condition of e7. (2 4ill 6e ta)en as:
(2
2'
>he anal3tical sol,tion to e7s. (' to (D ,4hich 4e ,se to e$al,ate the
n,merical M?L o,tp,t, is
(D2
>h,s, this pro6lem pro$ides ,s 4ith the means to ascertain precisel3 ho4 acc,rate
o,r method is, ,nder 4ell defined circ,mstances, 63 permittin: the n,merical
res,lts to 6e compared directl3 4ith the )no4n anal3tical sol,tion. 0erif3in: the
acc,rac3 of the method, 4hen ,sed to sol$e a representati$e set of pro6lems, :i$es
confidence that acc,rate res,lts 4ill 6e o6tained 4hen ,sin: the method to sol$e
pro6lems 4here the sol,tions are not )no4n apriori.
1 main pro:ram in +atlab for the M?L sol,tion of e7s. (' to (D 4ith the
anal3tical sol,tion, e7. (D2, incl,ded for comparison 4ith the M?L sol,tion, is
listed 6elo4.
N 8ile: pdeGmain.m
N Clear pre$io,s files
clear all
clc
N
N Parameters shared 4ith the ?@. ro,tine
:lo6al ncall ndss
N
N Initial condition
nE2'B
for iE':n
,0(iEsin((pi*2.0O(i='*(n='B
end
N
N Independent $aria6le for ?@. inte:ration
t0E0.0B
tfE2."B
to,tElinspace(t0,tf,nB
no,tEnB
ncallE0B
N
N ?@. inte:ration
mfE'B
reltolE'.0e=0DB a6stolE'.0e=0DB
optionsEodeset(J2el>olJ,reltol,J16s>olJ,a6stolB
if(mfEE' N eAplicit 8@s
22
(t,,+Eode'"s(PpdeG',to,t,,0,optionsB end
if(mfEE2 ndssEDB N ndss E 2, D, &, ! or '0 re7,ired
(t,,+Eode'"s(PpdeG2,to,t,,0,optionsB end
if(mfEEF ndssEDDB N ndss E D2, DD, D&, D! or "0 re7,ired
(t,,+Eode'"s(PpdeGF,to,t,,0,optionsB end
N
N Store n,merical and anal3tical sol,tions, errors at A E '*2
n2E(n='*2.0I'B
sineEsin(pi*2.0O0."B
for iE':no,t
,Gplot(iE,(i,n2B
,Ganal(iEeAp(=piQ2*D.0Ot(iOsineB
errGplot(iE,Gplot(i=,Ganal(iB
end
N
N @ispla3 selected o,tp,t
fprintf(JRn mf E N2d a6stol E N!.'e reltol E N!.'eRnJ,...
mf,a6stol,reltolB
fprintf(JRn t ,(0.",t ,Ganal(0.",t err ,(0.",tRnJB
for iE':":no,t
fprintf(JN&.FfN'".&fN'".&fN'".7fRnJ,...
t(i,,Gplot(i,,Ganal(i,errGplot(iB
end
fprintf(JRn ncall E NDdRnJ,ncallB
N
N Plot n,merical sol,tion and errors at A E '*2
fi:,re('B
s,6plot(',2,'
plot(t,,GplotB aAis ti:ht
title(J,(0.",t $s tJB Ala6el(JtJB 3la6el(J,(0.",tJ
s,6plot(',2,2
plot(t,errGplotB aAis ti:ht
title(J.rr ,(0.",t $s tJB Ala6el(JtJB 3la6el(J.rr ,(0.",tJ
print =deps pde.epsB print =dps pde.ps
N
N Plot n,merical sol,tion in F@ perspecti$e
fi:,re(2B
colormap(J-ra3JB
CEones(nB
:Elinspace(0,',nB N 8or distance A
h' E 4aterfall(t,:,,J,CB
aAis(Jti:htJB
2F
:rid off
Ala6el(Jt, timeJ
3la6el(JA, distanceJ
Cla6el(J,(A,tJ
s' E sprintf(J@iff,sion .7,ation = M?L Sol,tionJB
s>mp E sprintf(J,(A,0 E sin(RRpi A*2 JB
s2 E sprintf(JInitial condition: NsJ, s>mpB
title((Ss'T, Ss2T+, JfontsiCeJ, '2B
$ E ( 0.!&'& =0."07& 0.0000 =0.'770
0.F7'2 0.&F0' 0.&!20 =0.!D'7
0.FD&2 0."!7& =0.7F'F !.""#0
0 0 0 '.0000+B
$ie4($B
rotateFd onB
9e can note the follo4in: points a6o,t this main pro:ram:
1fter declarin: some parameters :lo6al so that the3 can 6e shared 4ith other
ro,tines called $ia this main pro:ram, initial condition (2 is comp,ted o$er a 2'=
point :rid in x.
N Clear pre$io,s files
clear all
clc
N
N Parameters shared 4ith the ?@. ro,tine
:lo6al ncall ndss
N
N Initial condition
nE2'B
for iE':n
,0(iEsin((pi*2.0O(i='*(n='B
end
>he independent $aria6le tis defined o$er the inter$al " . 2 0 t B a:ain, a 2'=
point :rid is ,sed.
N Independent $aria6le for ?@. inte:ration
t0E0.0B
tfE2."B
2D
to,tElinspace(t0,tf,nB
no,tEnB
ncallE0B
>he 2' ?@.s are then inte:rated 63 a call to the Matla6 inte:rator ode'"s.
mfE'B
reltolE'.0e=0DB a6stolE'.0e=0DB
optionsEodeset(J2el>olJ,reltol,J16s>olJ,a6stolB
if(mfEE' N eAplicit 8@s
(t,,+Eode'"s(PpdeG',to,t,,0,optionsB end
if(mfEE2 ndssEDB N ndss E 2, D, &, ! or '0 re7,ired
(t,,+Eode'"s(PpdeG2,to,t,,0,optionsB end
if(mfEEF ndssEDDB N ndss E D2, DD, D&, D! or "0 re7,ired
(t,,+Eode'"s(PpdeGF,to,t,,0,optionsB end
>hree cases are pro:rammed correspondin: to mf E ', 2, F, for 4hich three
different ?@.s ro,tines, pdeG' , pdeG2 , and pdeGF are called (these ro,tines are
disc,ssed s,6se7,entl3. >he $aria6le ndss refers to a li6rar3 of differentiation
ro,tines for ,se in the M?L sol,tion of P@.sB the ,se of ndss is ill,strated in the
s,6se7,ent disc,ssion. /ote that a stiff inte:rator, ode'"s , 4as selected 6eca,se
the 2' ?@.s are s,fficientl3 stiff that a nonstiff inte:rator res,lts in a lar:e
n,m6er of calls to the ?@. ro,tine.
Selected n,merical res,lts are stored for s,6se7,ent ta6,lar and plotted o,tp,t.
N Store n,merical and anal3tical sol,tions, errors at A E '*2
n2E(n='*2.0I'B
sineEsin(pi*2.0O0."B
for iE':no,t
,Gplot(iE,(i,n2B
,Ganal(iEeAp(=piQ2*D.0Ot(iOsineB
errGplot(iE,Gplot(i=,Ganal(iB
end
Selected ta6,lar n,merical o,tp,t is first displa3ed.
N @ispla3 selected o,tp,t
fprintf(JRn mf E N2d a6stol E N!.'e reltol E N!.'eRnJ,...
2"
mf,a6stol,reltolB
fprintf(JRn t ,(0.",t ,Ganal(0.",t err ,(0.",tRnJB
for iE':":no,t
fprintf(JN&.FfN'".&fN'".&fN'".7fRnJ,...
t(i,,Gplot(i,,Ganal(i,errGplot(iB
end
fprintf(JRn ncall E NDdRnJ,ncallB
>he o,tp,t from this code is:
mf E ' a6stol E '.0e=00D reltol E '.0e=00D
t ,(0.",t ,Ganal(0.",t err , (0.",t
0.000 0.707'07 0.707'07 0.0000000
0.&2" 0.'"'F!7 0.'"'2&! 0.000''!2
'.2"0 0.0F2F70 0.0F2F&0 0.00000#F
'.!7" 0.00&!#D 0.00&#2F =0.00002!F
2."00 0.00'D72 0.00'D!' =0.00000#'
ncall E !"
>his o,tp,t indicates that the M?L sol,tion a:rees 4ith the anal3tical sol,tion to
at least three si:nificant fi:,res. 1lso, ode'"s calls the deri$ati$e ro,tine onl3 !"
times (in contrast 4ith the nonstiff inte:rator odeD" that re7,ires approAimatel3
"000 = '0000 calls, 4hich clearl3 indicates the ad$anta:e of a stiff inte:rator for
this pro6lem.
>he M?L sol,tion and its error (comp,ted from the anal3tical sol,tion are
plotted.
N Plot n,merical sol,tion and errors at A E '*2
fi:,re('B
s,6plot(',2,'
plot(t,,GplotB aAis ti:ht
title(J,(0.",t $s tJB Ala6el(JtJB 3la6el(J,(0.",tJ
s,6plot(',2,2
plot(t,errGplotB aAis ti:ht
title(J.rr ,(0.",t $s tJB Ala6el(JtJB 3la6el(J.rr ,(0.",tJ
print =deps pde.epsB print =dps pde.ps
2&
>he plotted error o,tp,t 6elo4 indicates that the error in the M?L sol,tion $aried
6et4een approAimatel3
"
'0 F

and
"
'0 '&

4hich is not 7,ite 4ithin the
error ran:e specified in the pro:ram.
reltolE'.0e=0DB a6stolE'.0e=0DB
,i)ure 1- +./ second order solution error & explicit ,#s.
>he fact that these error tolerances 4ere not satisfied does not necessaril3 mean
that ode'"s failed to adH,st the inte:ration inter$al to meet these error tolerances.
2ather, the error of approAimatel3
D
'0 & . '

is d,e to the limited acc,rac3 of the
second order 8@ approAimation of
2
2
x
u

pro:rammed in pdeG' . >his concl,sion is


confirmed 4hen the main pro:ram calls pdeG2 (for mf E 2 or pdeGF (for mf E F
as disc,ssed s,6se7,entl3B these t4o ro,tines ha$e 8@ approAimations that are
more acc,rate than in pdeG' so the errors fall 6elo4 the specified tolerances.
>his anal3sis indicates that t4o so,rces of errors res,lt from the M?L sol,tion of
P@.s s,ch as e7.. (' :
'. errors d,e to the inte:ration in (63 ode'"s, and
2. errors d,e to the approAimation of the spatial deri$ati$es s,ch as
2
2
x
u


pro:rammed in the deri$ati$e ro,tine s,ch as pdeG'.
In other 4ords, 4e ha$e to 6e attenti$e to inte:ration errors in the initial and
boundary value independent variables.
In s,mmar3, a comparison of the n,merical and anal3tical sol,tions indicates that
2' :rid points in x 4ere not s,fficient 4hen ,sin: the second order 8@s in pdeG'.
Ho4e$er, in :eneral, 4e 4ill not ha$e an anal3tical sol,tion s,ch as e7. (D2 to
determine if the n,m6er of spatial :rid points is ade7,ate. In this case, some
27
eAperimentation 4ith the n,m6er of :rid points, and the o6ser$ation of the
res,ltin: sol,tions to infer the de:ree of acc,rac3 or spatial conver!ence' ma3 6e
re7,ired.
1 F@ plot is also prod,ced.
N Plot n,merical sol,tion in F@ perspecti$e
fi:,re(2B
colormap(J-ra3JB
CEones(nB
:Elinspace(0,',nB N 8or distance A
h' E 4aterfall(t,:,,J,CB
aAis(Jti:htJB
:rid off
Ala6el(Jt, timeJ
3la6el(JA, distanceJ
Cla6el(J,(A,tJ
s' E sprintf(J@iff,sion .7,ation = M?L Sol,tionJB
s>mp E sprintf(J,(A,0 E sin(RRpi A*2 JB
s2 E sprintf(JInitial condition: NsJ, s>mpB
title((Ss'T, Ss2T+, JfontsiCeJ, '2B
$ E (0.!&'& =0."07& 0.0000 =0.'770
0.F7'2 0.&F0' 0.&!20 =0.!D'7
0.FD&2 0."!7& =0.7F'F !.""#0
0 0 0 '.0000+B
$ie4($B
rotateFd onB
>he plotted o,tp,t 6elo4 clearl3 indicates the ori:in of the lines in the method of
lines
2!
,i)ure *- .ri)in of the lines in the %ethod of +ines.
>he pro:rammin: of the approAimatin: M?L*?@.s is in one of the three ro,tines
called 63 ode'"s. 9e no4 consider each of these ro,tines. 8or mf E ', pdeG' calls
f,nction ,tEpdeG'(t,,.
N 8ile: pdeG'.m
f,nction ,tEpdeG'(t,,
N
N Pro6lem parameters
:lo6al ncall
AlE0.0B
A,E'.0B
N
N P@.
nElen:th(,B
dA2E((A,=Al*(n='Q2B
for iE':n
if(iEE' ,t(iE0.0B
elseif(iEEn ,t(iE2.0O(,(i='=,(i*dA2B
else ,t(iE(,(iI'=2.0O,(iI,(i='*dA2B
end
end
,tE,tJB
2#
N
N Increment calls to pdeG'
ncallEncallI'B
9e can note the follo4in: points a6o,t pdeG':
Some pro6lem parameters are first defined.
f,nction ,tEpdeG'(t,,
N
N Pro6lem parameters
:lo6al ncall
AlE0.0B
A,E'.0B
Al and A, co,ld ha$e also 6een set in the main pro:ram and passed to pdeG' as
:lo6al $aria6les. >he definin: statement at the 6e:innin: of pdeG' indicates that
the independent $aria6le t and dependent $aria6le $ector , are inp,ts to pdeG',
4hile the o,tp,t is the $ector of t der$ati$es, ,t B in other 4ords, all of the n ?@.
deri$ati$es in t m,st 6e defined in pdeG'.
>he finite difference approAimation of e7. (' is then pro:rammed.
N P@.
nElen:th(,B
dA2E((A,=Al*(n='Q2B
for iE':n
if(iEE' ,t(iE0.0B
elseif(iEEn ,t(iE2.0O(,(i='=,(i*dA2B
else ,t(iE(,(iI'=2.0O,(iI,(i='*dA2B
end
end
,tE,tJB
>he n,m6er of ?@.s (2' is determined 63 the len:th command nElen:th(,B so
that the pro:rammin: is :eneral (the n,m6er of ?@.s can easil3 6e chan:ed in the
main pro:ram. >he s7,are of the 8@ inter$al, dA2, is then comp,ted.
>he M?L pro:rammin: of the 2' ?@.s is done in the for loop. 8or BC (F , the
codin: is
F0
if(iEE' ,t(iE0.0B
since the $al,e of u(xE0,tE0 does not chan:e after 6ein: set as an initial condition
in the main pro:ram (and therefore its time deri$ati$e is Cero.
8or BC (D , the codin: is
elseif(iEEn ,t(iE2.0O(,(i='=,(i*dA2B
4hich follo4s directl3 from the 8@ approAimation of BC (D ( e7. (F7
or 4ith
/ote that the fictitious value u(nI' can then 6e replaced in the ?@. at 63
u(n ='.
8or the remainin: interior points, the pro:rammin: is
else ,t(iE(,(iI'=2.0O,(iI,(i='*dA2B
4hich follo4s from the 8@ approAimation of the second deri$ati$e (e7. (FF
Since the Matla6 ?@. inte:rators re7,ire a col,mn $ector of deri$ati$es, a final
transpose of ,t is re7,ired.
,tE,tJB
N
N Increment calls to pdeG'
ncallEncallI'B
8inall3, the n,m6er of calls to pdeG' is incremented so that at the end of the
sol,tion, the $al,e of ncall displa3ed 63 the main pro:ram :i$es an indication of
F'
the comp,tational effort re7,ired to prod,ce the entire sol,tion. >he n,merical and
:raphical o,tp,t for this case (mfE' 4as disc,ssed pre$io,sl3.
8or mfE2, f,nction pdeG2 is called 63 ode'"s.
N 8ile: pdeG2.m
f,nction ,tEpdeG2(t,,
N
N Pro6lem parameters
:lo6al ncall ndss
AlE0.0B
A,E'.0B
N
N BC at A E 0 (@irichlet
,('E0.0B
N
N Calc,late ,A
nElen:th(,B
if (ndssEE 2 ,AEdss002(Al,A,,n,,B N second order
elseif(ndssEE D ,AEdss00D(Al,A,,n,,B N fo,rth order
elseif(ndssEE & ,AEdss00&(Al,A,,n,,B N siAth order
elseif(ndssEE ! ,AEdss00!(Al,A,,n,,B N ei:hth order
elseif(ndssEE'0 ,AEdss0'0(Al,A,,n,,B N tenth order
end
N
N BC at A E ' (/e,mann
,A(nE0.0B
N
N Calc,late ,AA
if (ndssEE 2 ,AAEdss002(Al,A,,n,,AB N second order
elseif(ndssEE D ,AAEdss00D(Al,A,,n,,AB N fo,rth order
elseif(ndssEE & ,AAEdss00&(Al,A,,n,,AB N siAth order
elseif(ndssEE ! ,AAEdss00!(Al,A,,n,,AB N ei:hth order
elseif(ndssEE'0 ,AAEdss0'0(Al,A,,n,,AB N tenth order
end
N
N P@.
,tE,AAJB
,t('E0.0B
N
N Increment calls to pdeG2
ncallEncallI'B
F2
9e can note the follo4in: points a6o,t pdeG2:
>he initial statements are the same as in pdeG'. >hen the @irichlet BC at x E 0 is
pro:rammed.
N BC at A E 0 (@irichlet
,('E0.0B
1c,all3, the statement ,('E0.0B has no effect since the dependent $aria6les can
onl3 6e chan:ed thro,:h their deri$ati$es, i.e., ,t(', in the ?@. deri$ati$e
ro,tine. >his code 4as incl,ded H,st to ser$e as a reminder of the BC at x E 0,
4hich is pro:rammed s,6se7,entl3.
>he first order spatial deri$ati$e
x
u
x
u
=

, is then comp,ted
N Calc,late ,A
nElen:th(,B
if (ndssEE2 ,AEdss002(Al,A,,n,,B N second order
elseif(ndssEE D ,AEdss00D(Al,A,,n,,B N fo,rth order
elseif(ndssEE & ,AEdss00&(Al,A,,n,,B N siAth order
elseif(ndssEE ! ,AEdss00!(Al,A,,n,,B N ei:hth order
elseif(ndssEE'0 ,AEdss0'0(Al,A,,n,,B N tenth order
end
8i$e li6rar3 ro,tines, dss002 to dss0'0, are pro:rammed that ,se second order to
tenth order 8@ approAimations, respecti$el3. Since ndssED is specified in the main
pro:ram, dss00D is ,sed in the calc,lation of ,A.
BC (D is then applied follo4ed 63 the calc,lation of the second order spatial
deri$ati$e from the first order spatial deri$ati$e.
N BC at A E ' (/e,mann
,A(nE0.0B
N
N Calc,late ,AA
if (ndssEE 2 ,AAEdss002(Al,A,,n,,AB N second order
elseif(ndssEE D ,AAEdss00D(Al,A,,n,,AB N fo,rth order
elseif(ndssEE & ,AAEdss00&(Al,A,,n,,AB N siAth order
elseif(ndssEE ! ,AAEdss00!(Al,A,,n,,AB N ei:hth order
FF
elseif(ndssEE'0 ,AAEdss0'0(Al,A,,n,,AB N tenth order
end
1:ain, dss00D is called 4hich is the ,s,al proced,re (the order of the 8@
approAimation :enerall3 is not chan:ed in comp,tin: hi:her order deri$ati$es
from lo4er order deri$ati$es, a process termed sta!ewise differentiation.
8inall3, e7. (' is pro:rammed and the @irichlet BC at xE0 (e7. (F is applied.
N P@.
,tE,AAJB
,t('E0.0B
N
N Increment calls to pdeG2
ncallEncallI'B
/ote the similarit3 of the code to the P@. (e7.(', and also the transpose re7,ired
63 ode'"s.
>he n,merical o,tp,t for this case (mfE2 is:
mf E 2 a6stol E '.0e=00D reltol E '.0e=00D
t ,(0.",t ,Ganal(0.",t err ,(0.",t
0.000 0.707'07 0.707'07 0.0000000
0.&2" 0.'"'2&7 0.'"'2&! =0.00000'F
'.2"0 0.0F2F'! 0.0F2F&0 =0.0000D'!
'.!7" 0.00&!7! 0.00&#2F =0.0000DD&
2."00 0.00'D&7 0.00'D!' =0.0000'F!
ncall E &2
>he plotted error o,tp,t 6elo4 indicates that the error in the M?L sol,tion $aried
6et4een approAimatel3
"
'0 "

and
"
'0 2 . F

4hich is 4ithin the error ran:e
specified in the pro:ram.
reltolE'.0e=0DB a6stolE'.0e=0DB
FD
,i)ure 0- +./ fourth$order solution error & ,#s by dss!!1 library routine.
>h,s, s4itchin: from the second order 8@s in pdeG' to fo,rth order finite
differences in pdeG2 red,ced the spatial truncation error so that the M?L sol,tion
met the specified error tolerances.
8or mf E F, f,nction pdeGF is called 63 ode'"s.
N 8ile: pdeGF.m
f,nction ,tEpdeGF(t,,
N
N Pro6lem parameters
:lo6al ncall ndss
AlE0.0B
A,E'.0B
N
N BC at A E 0
,('E0.0B
N
N BC at A E '
nElen:th(,B
,A(nE0.0B
N
N Calc,late ,AA
nlE'B N @irichlet
n,E2B N /e,mann
if (ndssEED2 ,AAEdss0D2(Al,A,,n,,,,A,nl,n,B N second order
elseif(ndssEEDD ,AAEdss0DD(Al,A,,n,,,,A,nl,n,B N fo,rth order
elseif(ndssEED& ,AAEdss0D&(Al,A,,n,,,,A,nl,n,B N siAth order
elseif(ndssEED! ,AAEdss0D!(Al,A,,n,,,,A,nl,n,B N ei:hth order
F"
elseif(ndssEE"0 ,AAEdss0"0(Al,A,,n,,,,A,nl,n,B N tenth order
end
N
N P@.
,tE,AAJB
,t('E0.0B
N
N Increment calls to pdeGF
ncallEncallI'B
9e can note the follo4in: points a6o,t pdeGF:
>he initial statements are the same as in pdeG'. >hen the @irichlet BC at xE0 and
the /e,mann BC at xE' are pro:rammed.
f,nction ,tEpdeGF(t,,
N
N Pro6lem parameters
:lo6al ncall ndss
AlE0.0B
A,E'.0B
N
N BC at A E 0
,('E0.0B
N
N BC at A E '
nElen:th(,B
,A(nE0.0B
1:ain, the statement ,('E0.0B has no effect (since the dependent $aria6les can
onl3 6e chan:ed thro,:h their deri$ati$es, i.e., ,t(', in the ?@. deri$ati$e
ro,tine. >his code 4as incl,ded H,st to ser$e as a reminder of the BC at ,
4hich is pro:rammed s,6se7,entl3.
>he second order spatial deri$ati$e,
xx
u
x
u
=

2
2
, is then comp,ted.
N Calc,late ,AA
F&
nlE'B N @irichlet
n,E2B N /e,mann
if (ndssEED2 ,AAEdss0D2(Al,A,,n,,,,A,nl,n,B N second order
elseif(ndssEEDD ,AAEdss0DD(Al,A,,n,,,,A,nl,n,B N fo,rth order
elseif(ndssEED& ,AAEdss0D&(Al,A,,n,,,,A,nl,n,B N siAth order
elseif(ndssEED! ,AAEdss0D!(Al,A,,n,,,,A,nl,n,B N ei:hth order
elseif(ndssEE"0 ,AAEdss0"0(Al,A,,n,,,,A,nl,n,B N tenth order
end
8i$e li6rar3 ro,tines, dss0D2 to dss0"0, are pro:rammed that ,se second order to
tenth order 8@ approAimations, respecti$el3 for a second deri$ati$e. Since
ndssEDD is specified in the main pro:ram, dss00DD is ,sed in the calc,lation of ,AA.
1lso, these differentiation ro,tines ha$e t4o parameters that specif3 the t3pe of
BCs:
'. nl E ' or 2 specif3 a @irichlet or a /e,mann BC, respecti$el3, at the lo4er
6o,ndar3 $al,e of xExl(E0B in this case, BC (F is @irichlet, so nl E ', and
2. n, E ' or 2 specif3 a @irichlet or a /e,mann BC, respecti$el3, at the ,pper
6o,ndar3 $al,e of xExu(E'B in this case, BC (D is /e,mann, so n, E 2.
8inall3, e7. (' is pro:rammed and the @irichlet BC at xE0(e7. (F , is applied.
N P@.
,tE,AAJB
,t('E0.0B
N
N Increment calls to pdeGF
ncallEncallI'B
1:ain, the transpose is re7,ired 63 ode'"s.
>he n,merical o,tp,t for this case (mfEF is:
mf E F a6stol E '.0e=00D reltol E '.0e=00D
t ,(0.",t ,Ganal(0.",t err ,(0.",t
0.000 0.707'07 0.707'07 0.0000000
0.&2" 0.'"'2&7 0.'"'2&! =0.00000'7
'.2"0 0.0F2F'! 0.0F2F&0 =0.0000D20
'.!7" 0.00&!7! 0.00&#2F =0.0000DD7
F7
2."00 0.00'D&7 0.00'D!' =0.0000'F!
ncall E &2
>he plotted error o,tp,t 6elo4 indicates that the error in the M?L sol,tion $aried
6et4een approAimatel3
"
'0 ! . D

and
"
'0 2 . F

4hich is 4ithin the error
ran:e specified in the pro:ram.
reltolE'.0e=0DB a6stolE'.0e=0DB
9e concl,de this eAample 4ith the follo4in: o6ser$ation:
1s the sol,tion approaches stead3 state,
0 ,
t
u t
and from e7. (' ,
0
xx
u
.
1s the second deri$ati$e $anishes, the sol,tion 6ecomes:
,i)ure 1- +./ fourth$order solution error & ,#s by dss!11 library routine.
>h,s, the stead3 state sol,tion is linear in x, 4hich can ser$e as another chec) on
the n,merical sol,tion (for BCs (F and (D , c
'
Ec
2
E0 and th,s at stead3 state
uE0 4hich also follo4s from the anal3tical sol,tion, e7. (D2. >his t3pe of special
case anal3sis is often ,sef,l in chec)in: a n,merical sol,tion. In addition to
mathematical conditions s,ch as the linear dependenc3 on x, ph3sical conditions
F!
can fre7,entl3 also 6e ,sed to chec) sol,tions, e.:., conser$ation of mass,
moment,m and ener:3.
>hro,:h this eAample application 4e ha$e attempted to ill,strate the 6asic steps of
M?L*P@. anal3sis to arri$e at a n,merical sol,tion of accepta6le acc,rac3. 9e
ha$e also presented some 6asic ideas for assessin: acc,rac3 4ith respect to time
and space (i.e. t and x. More ad$anced applications (e.:., pro6lems eApressed as
s3stems of nonlinear P@.s can 6e anal3Ced ,sin: the same ideas disc,ssed in this
eAample.
1,thor 9illiam .. Schiesser 4ill 6e :lad to assist 63 pro$idin: codes for other
'@, 2@ and F@ P@. pro6lems. In an3 re7,est please incl,de 3o,r name,
affiliation and postal mailin: address so that 4e can )eep 3o, informed of an3
chan:es*additions to the Matla6 codes.
2,nnin: this eAample
Cop3 and paste the follo4in: Matla6 ro,tines descri6ed a6o$e:
pdeGmain.m, pdeG'.m, pdeG2.m and pdeGF.m
Cop3 and paste the follo4in: Matla6 li6rar3 codes:
= 8irst @eri$ati$e ro,tines: dss002.m, dss00D.m, dss00&.m, dss00!.m and
dss0'0.m
= Second @eri$ati$e ro,tines: dss0D2.m, dss0DD.m, dss0D&.m, dss0D!.m and
dss0"0.m
Cop3 all Matla6 files into the same director3 and r,n pdeGmain.m
>o eAperiment, tr3 chan:in: the $ario,s options descri6ed a6o$e.
F#

You might also like