You are on page 1of 27

Finite Difference Mathods for Parabolic Partial Differential Equations

The Basics David Gavaghan

DTC Mathematical Biology Course

Author

Short Paper Title

Lecture Summary
Mathematical prerequisites
Solution of the diffusion equation by separation of variables Taylors Theorem

The explicit Finite Difference method for the diffusion equation


Truncation Error Analysis Fourier Error Analysis Convergence, consistency and stability of numerical algorithms

The implicit -method for the diffusion equation Reaction diffusion systems Other Issues aternative bounday conditions and higher dimensions

Author

Short Paper Title

Numerical Solution of Partial Differential Equations


Very few partial differential equations arising in biology can be solved analytically and numerical approximation methods are therefore an essential element in the mathematical biologists toolkit Several standard numerical methods in common use
Finite element methods (elliptic problems, complexgeometries) Finite volume methods (hyperbolic problems) Finite Difference Methods (simple geometries, parabolic problems, 1D problems)

Finite Difference methods are the usual entry point and the simplest to understand and code up Finite element methods will be covered in the computational biology course
Author Short Paper Title

Model Problem

We will take as our model problem the diffusion equation in one space dimension u 2u = t x 2 for [x, t] [0, 1] [0, T ]

where u(x, t) is the dependent variable (concentration, for example) dened for, with zero Dirichlet boundary conditions u(0, t) = u(1, t) = 0 for all t, and initial condition u(x, 0) = u 0 (x).

Author

Short Paper Title

Solution of the Model Problem

This simple equation can be solved by separation of variables. We assume thaat the solution u(x, T ) can be expressed as u(x, t) = X (x)T (t) Substituting into the pde gives T X X (x)T (t) = TX => = = constant = 2 , T X say.

Author

Short Paper Title

Solution of the Model Problem

This now gives us two simple odes to solve for T and X giving T (t) = C exp 2 t X (x) = Aeix + Beix = A sin x + B cos x where A , B , C and are constants which can be determined to satisfy the boundary and initial conditions. From the boundary conditions it is clear that B = 0 and = n for all integers n 1 (exercise).

Author

Short Paper Title

Solution of the Model Problem

The general solution is given by the sum of all such solutions i.e.

u(x, t) =
n=1

Dn sin(nx) exp (n2 2 t)

and
1

Dn = 2
0

u 0 (x) sin(nx) dx

Author

Short Paper Title

Taylors Theorem

The basis of nite difference methods is Taylors Theorem, which roughly speaking states that any sufciently smooth function can be approximated locally by a polynomial.

Author

Short Paper Title

Taylors Theorem

Formally, the theorem states that if n 0 is an integer and f is a function which is continuously differentiable n times on the closed interval [a, x] and n + 1 times differentiable on the open interval (a, x), then f (x) = f (a) + (x a)f (a) + (x a)2 f +(x where Rn (x) =
f (n+1) () (x (n+1)!
(n) (a) a)n f n!

(a) 2!

+ ...

+ Rn (x)

a)n+1 for some (a, x).

Author

Short Paper Title

Taylors Theorem
This is more useful to us if we write it as f (x + x) f (x) + xf (x) + x 2 f
(x) 2!

+ . . . + x n f

(n) (x)

n!

We can straightforwardly extend this to two dimensions f (x + x, y + y ) = f (x, y ) + [xfx (x, y ) + yfy (x, y )] + 1 x 2 fxx (x, y ) + 2xyfxy (x, y ) + y 2 fyy (x, y ) + 2! 1 x 3 fxxx (x, y ) + 3x 2 yfxxy (x, y )+ 3! 3xy 2 fxyy (x, y ) + y 3 fyyy + . . .

which we will need in analysing the truncation errors in our nite difference schemes.

Author

Short Paper Title

Finite Difference Approximations for the Derivatives in the Model Problem


In the model problem we wish to replace the partial derivatives in t and x by their nite difference approximations. From the two variable Taylor Series above, if we discretise time in equal timesteps t and space in equal spacesteps x (see diagram) we can then expand the solution u about the point u(x, t + t) to obtain u(x, t + t) = u(x, t) + tut (x, t) + t 2 Re-arranging gives utt (x, t) u(x, t + t) u(x, t) = ut (x, t) + t + ... t 2!
Author Short Paper Title

utt (x, t) + ... 2!

Space discretisation
and for the space derivatives we consider u(t, x + x), u(x, t), and u(t, x x) u(x + x, t) = u(x, t) + xux (x, t) + x 2 u(x, t) = u(x, t) u(x x, t) = u(x, t) xux (x, t) + x 2 uxx (x, t) + ... 2! uxx (x, t) + ... 2!

If we now add the rst and third equations above, subtract twice the second, and divide by x 2 , we obtain u(x + x, t) 2u(x, t) + u(x x, t) uxxxx (x, t) = uxx (x, t) + 2x 2 + ... x 2 4!

Author

Short Paper Title

Finite Difference Representation


If we now dene our time and space discretistion to be the points (x, t) = (jx, nt), for j = 0, 1, . . . , J and n = 0, 1, . . . (see diagram) then we can dene the nite difference approximation to be Ujn u(xj , tn ) = u(jx, nt), and our approximations to the derivatives using the Taylor expansions and substituting into the partial differential equation give Ujn+1 Ujn t =
n n Uj+1 2Ujn + Uj1 . x 2

This is the simple explicit nite difference approximation to the model problem.

Author

Short Paper Title

Truncation error
The truncation error, T (x, t), of a nite difference scheme is dened as the difference between the two sides of the above equation when the approximation Ujn is replaced by the exact solution u(xj , tn ), that is T (x, t) = so that 1 1 T (x, t) = (ut uxx ) + ( utt t uxxxx (x)2 + . . . 2 12 1 1 = utt t uxxxx (x)2 + . . . 2 12 That is, it is rst order in time and second order in space. u(x, t + t) u(x, t) u(x + x, t) 2u(x, t) + u(x x, t) t (x)2

Author

Short Paper Title

Fourier Stability Theory


In the same way as the exact solution of the differential equation can be expressed as a Fourier series (based on the observation that a particular set of Fourier modes are exact solutions of the pde), we can show that a similar Fourier mode is an exact solution of the difference equations. Consider the discrete Fourier mode Ujn = n eik (jx) for some constant k .

Author

Short Paper Title

Fourier Stability Theory


If we write the difference equations in the form
n Ujn+1 = Ujn + (Uj+1 2Ujn + Uj1 )

where =

t x 2

we can note that Ujn+1 = n+1 eik (jx) = Ujn

we can substitute into the difference equation to obtain = (k ) = 1 + (eik x 2 + eik x ) = 1 2(1 cos k x) 1 = 1 4 sin2 k x 2

Author

Short Paper Title

Fourier Stability Theory


For stability we require that || 1 => 1 2

As for the analytic solution of the pde, we can satisfy the bounday conditions by taking k = m and obtain the general solution of the difference equations. We can also substitute this into our equation for (k ) above and expand as a Talyor series to obtain an alternative approach to establishing the order of convergence. See p20 of Morton and Mayers for details.

Author

Short Paper Title

Method of Lines

This is a very useful technique when solving 1-D problems if you have a very good ODE solver available (as in Matlab). In this method we discretise only the spatial component (i.e. the x-direction) of the pde to obtain a system of ordinary diffetential equations for each x-"line". [See diagram.] i.e. we solve continuously in imie for each mesh line Uj (t) with Uj (0) = u 0 (jx).

Author

Short Paper Title

Method of Lines (contd)


So, using Taylor-expansions in the x-direction only we obtain (and implementing the zero bcs) we obtain dU1 2U1 (t) + U2 (t) = , U1 (0) = u 0 (x) 2 dt x dU2 U1 (t) 2U2 (t) + U3 (t) = , U2 (0) = u 0 (2x) dt x 2 . . . dUJ1 UJ2 (t) 2UJ1 (t) = , UJ1 (0) = u 0 ((J 1)x) dt x 2

Author

Short Paper Title

Implicit Finite Difference Representation

The restriction on the timetep imposed by stability considerations when using the explicit nite difference method can be overcome and we can obtain a more stable nite difference scheme by using the "current" time level in approximating the spacial derivatives in the PDE. This results in an "implicit" nite difference scheme The penalty is that we now have to solve a linear system of equations.

Author

Short Paper Title

Implicit Finite Difference Representation


Replacing the spatial derivatives in the pde by the nite difference approximation at time level n + 1 gives Ujn+1 Ujn t Setting =
t x 2 n+1 n+1 Uj+1 2Ujn+1 + Uj1

x 2

and re-arranging gives

n+1 n+1 Uj1 + (1 + 2)Ujn+1 Uj+1 = Ujn

Author

Short Paper Title

Implicit Finite Difference Representation


This is a linear system of equations of size (J 1) (J 1): AU n+1 = U n with A= 1 + 2 0 1 + 2 0 1 + 2 0 0 0 0 0 0 0 0 1 + 2 1 + 2 ,

Author

Short Paper Title

The -Method

Replacing the spatial derivatives in the pde by a weighted average of the nite difference approximations at time levels n and n + 1 gives the method Ujn+1 Ujn t =
n+1 n+1 Uj+1 2Ujn+1 + Uj1

x 2
n n Uj+1 2Ujn + Uj1 x 2

+(1 ) [See exercises].

Author

Short Paper Title

Reaction Diffusion Equations

So far we have considered numerical methods for the heat/diffusion equation only. It is straightforward to extend this treatment to reaction-diffusion equations of the type seen very frequently in Mathematical Biology. This is typically done by treating any reaction terms explicitly regardless of how the diffusion term is treated (explicitly or implicitly)

Author

Short Paper Title

Reaction Diffusion Equations


e.g. Fishers equation is given (in 1D) by u 2u = + u(1 u) t x 2 At each timestep we simply replace the reaction term by the approximation u(1 u) Ujn (1 Ujn ) which is known either from the initiala conditions or from the previous timestep.

Author

Short Paper Title

Systems of Reaction Diffusion Equations


Systems of reaction diffusion equations can be solved numerically in an entirely analogous manner. e.g. for Schnakenburg kinetics u 2u + (a u + u 2 v ) = t x 2 v 2v = + (b u 2 v ) t x 2 we can treat the reaction terms explicitly and solve at each timestep as two separate systems of equations (solved either explicitly or implicitly) - otherwise we would need to solve as a single, (monolithic) non-linear system. Alternatively you could again use the method of lines.
Author Short Paper Title

Other Issues

Non-zero Dirichlet can be incorporated directly into the nite difference stencil and transferred to the right hand side of the equation. Zero-ux easiest to introduce a "ctitious mesh line" just outside the boundary. Higher Dimensions all of the above extends quite straightforwardly into higher spatial dimensions.

Author

Short Paper Title

You might also like