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.

74 Chapter 2. Solution of Linear Algebraic Equations<br />

The whole procedure requires only 3N 2 multiplies and a like number of adds (an<br />

even smaller number if u or v is a unit vector).<br />

The Sherman-Morrison formula can be directly applied to a class of sparse<br />

problems. If you already have a fast way of calculating the inverse of A (e.g., a<br />

tridiagonal matrix, or some other standard sparse form), then (2.7.4)–(2.7.5) allow<br />

you to build up to your related but more complicated form, adding for example a<br />

row or column at a time. Notice that you can apply the Sherman-Morrison formula<br />

more than once successively, using at each stage the most recent update of A −1<br />

(equation 2.7.5). Of course, if you have to modify every row, then you are back to<br />

an N 3 method. The constant in front of the N 3 is only a few times worse than the<br />

better direct methods, but you have deprived yourself of the stabilizing advantages<br />

of pivoting — so be careful.<br />

For some other sparse problems, the Sherman-Morrison formula cannot be<br />

directly applied for the simple reason that storage of the whole inverse matrix A −1<br />

is not feasible. If you want to add only a single correction of the form u ⊗ v,<br />

and solve the linear system<br />

(A + u ⊗ v) · x = b (2.7.6)<br />

then you proceed as follows. Using the fast method that is presumed available for<br />

the matrix A, solve the two auxiliary problems<br />

A · y = b A· z = u (2.7.7)<br />

for the vectors y and z. In terms of these,<br />

� �<br />

v · y<br />

x = y −<br />

z<br />

1+(v · z)<br />

(2.7.8)<br />

as we see by multiplying (2.7.2) on the right by b.<br />

Cyclic Tridiagonal Systems<br />

So-called cyclic tridiagonal systems occur quite frequently, and are a good<br />

example of how to use the Sherman-Morrison formula in the manner just described.<br />

The equations have the form<br />

⎡<br />

⎤ ⎡ ⎤ ⎡ ⎤<br />

b1 c1 0 ··· β<br />

⎢ a2<br />

⎢<br />

⎣<br />

b2 c2 ···<br />

···<br />

··· aN−1 bN−1 cN−1<br />

α ··· 0 aN bN<br />

⎥<br />

⎦ ·<br />

⎢<br />

⎣<br />

x1<br />

x2<br />

···<br />

xN−1<br />

xN<br />

⎥<br />

⎦ =<br />

⎢<br />

⎣<br />

r1<br />

r2<br />

···<br />

rN−1<br />

rN<br />

⎥<br />

⎦ (2.7.9)<br />

This is a tridiagonal system, except for the matrix elements α and β in the corners.<br />

Forms like this are typically generated by finite-differencing differential equations<br />

with periodic boundary conditions (§19.4).<br />

We use the Sherman-Morrison formula, treating the system as tridiagonal plus<br />

a correction. In the notation of equation (2.7.6), define vectors u and v to be<br />

⎡ ⎤ ⎡ ⎤<br />

γ<br />

⎢ 0.<br />

⎥<br />

⎢ ⎥<br />

u = ⎢ .<br />

⎥<br />

⎣<br />

0<br />

⎦<br />

α<br />

⎢<br />

v = ⎢<br />

⎣<br />

1<br />

0.<br />

.<br />

0<br />

β/γ<br />

⎥<br />

⎦<br />

(2.7.10)<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!