previous up next print clean
Next: The xxz derivative Up: FINITE DIFFERENCING Previous: The Crank-Nicolson method

Solving tridiagonal simultaneous equations

Much of the world's scientific computing power gets used up solving tridiagonal simultaneous equations. For reference and completeness the algorithm is included here.

Let the simultaneous equations be written as a difference equation  
 \begin{displaymath}
a_j \, q_{j+1} \ +\ b_j \, q_j \ +\ c_j \, q_{j-1}
 \eq d_j\end{displaymath} (39)
Introduce new unknowns ej and fj, along with an equation  
 \begin{displaymath}
q_j \eq e_j \, q_{j+1} \ +\ f_j\end{displaymath} (40)
Write (40) with shifted index:  
 \begin{displaymath}
q_{j-1} \eq e_{j-1} \, q_j \ +\ f_{j-1}\end{displaymath} (41)
Insert (41) into (39):  
 \begin{displaymath}
a_j \, q_{j+1} \ +\ b_j \, q_j \ +\ 
c_j \, ( e_{j-1} \, q_j \ +\ f_{j-1} ) \eq d_j\end{displaymath} (42)
Now rearrange (42) to resemble (15):  
 \begin{displaymath}
q_j \eq 
{ - \ a_j \over b_j \ +\ c_j \, e_{j-1} } \ \ q_{j+...
 ... +\ \ { d_j \ -\ c_j \, f_{j-1} \over b_j \ +\ c_j \, e_{j-1} }\end{displaymath} (43)
Compare (43) to (40) to see recursions for the new unknowns ej and fj:
      \begin{eqnarray}
e_j \ \ \ & = & \ \ \ { - \ a_j \over b_j \ +\ c_j \, e_{j-1} }...
 ... \ \ \ 
 { d_j \ -\ c_j \, f_{j-1} \over b_j \ +\ c_j \, e_{j-1} }\end{eqnarray} (44)
(45)

First a boundary condition for the left-hand side must be given. This may involve one or two points. The most general possible end condition is a linear relation like equation (40) at j=0, namely, $q_0 \ =\ e_0 q_1 + f_0$.Thus, the boundary condition must give us both e0 and f0. With e0 and all the aj , bj , cj, we can use (44) to compute all the ej.

On the right-hand boundary we need a boundary condition. The general two-point boundary condition is  
 \begin{displaymath}
c_{n-1} \, q_{n-1} \ +\ e_{\rm right} \, q_n \eq d_n\end{displaymath} (46)
Equation (46) includes as special cases the zero-value and zero-slope boundary conditions. Equation (46) can be compared to equation (41) at its end.  
 \begin{displaymath}
q_{n-1} \eq e_{n-1} \, q_n \ +\ f_{n-1}\end{displaymath} (47)
Both qn and qn-1 are unknown, but in equations (46) and (47) we have two equations, so the solution is easy. The final step is to take the value of qn and use it in (41) to compute $q_{n-1} , \ q_{n-2} , \ q_{n-3} , \ $ etc. The subroutine rtris() solves equation (38) for q where n=5, endl$=e_{\rm left}$,endr$=e_{\rm right}$,a=c$=-\alpha$, and b$=1-2\alpha$.

If you wish to squeeze every last ounce of power from your computer, note some facts about this algorithm. (1) The calculation of ej depends on the medium through aj, bj, cj, but it does not depend on the solution qj (even through dj). This means that it may be possible to save and reuse ej. (2) In many computers, division is much slower than multiplication. Thus, the divisor in (19a,b) can be inverted once (and perhaps stored for reuse).


previous up next print clean
Next: The xxz derivative Up: FINITE DIFFERENCING Previous: The Crank-Nicolson method
Stanford Exploration Project
10/31/1997