17.11.2012 Views

Numerical recipes

Numerical recipes

Numerical recipes

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

850 Chapter 19. Partial Differential Equations<br />

(a)<br />

t or n<br />

x or j<br />

FTCS<br />

(b) Fully Implicit<br />

(c) Crank-Nicolson<br />

Figure 19.2.1. Three differencing schemes for diffusive problems (shown as in Figure 19.1.2). (a)<br />

Forward Time Center Space is first-order accurate, but stable only for sufficiently small timesteps. (b) Fully<br />

Implicit is stable for arbitrarily large timesteps, but is still only first-order accurate. (c) Crank-Nicolson<br />

is second-order accurate, and is usually stable for large timesteps.<br />

Then<br />

becomes<br />

∂u<br />

∂t<br />

∂u<br />

∂t<br />

∂<br />

=<br />

∂x D(x)∂u<br />

∂x<br />

1 ∂<br />

=<br />

D(y)<br />

2u ∂y2 (19.2.16)<br />

(19.2.17)<br />

and we evaluate D at the appropriate yj. Heuristically, the stability criterion (19.2.6)<br />

in an explicit scheme becomes<br />

� �<br />

∆t ≤ min<br />

(19.2.18)<br />

j<br />

(∆y) 2<br />

2D −1<br />

j<br />

Note that constant spacing ∆y in y does not imply constant spacing in x.<br />

An alternative method that does not require analytically tractable forms for<br />

D is simply to difference equation (19.2.16) as it stands, centering everything<br />

appropriately. Thus the FTCS method becomes<br />

where<br />

u n+1<br />

j − unj ∆t<br />

= D j+1/2(u n j+1 − un j ) − D j−1/2(u n j − un j−1 )<br />

(∆x) 2<br />

(19.2.19)<br />

D j+1/2 ≡ D(x j+1/2) (19.2.20)<br />

Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5)<br />

Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by <strong>Numerical</strong> Recipes Software.<br />

Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copying of machinereadable<br />

files (including this one) to any server computer, is strictly prohibited. To order <strong>Numerical</strong> Recipes books or CDROMs, visit website<br />

http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!