Prev
Unit 3 · Linear Systems: Direct Methods
Cholesky, Banded and Tridiagonal Systems
60m100 XP
Next
🧮Linear Systems: Direct Methods

Cholesky, Banded and Tridiagonal Systems

Symmetric positive definite matrices and energy, A = LLᵀ, band storage and the Thomas algorithm

Crete, 1907
André-Louis Cholesky, a graduate of the École Polytechnique, is an officer of the French artillery assigned to the army's geographic service. Between 1907 and 1908 he surveys Crete; later, North Africa. A survey network is a web of triangles, with angles and distances measured more times than strictly necessary, and every measurement slightly wrong. Fitting the best coordinates to all of them by least squares produces a system of linear equations whose matrix is symmetric — and has one more property that Cholesky exploits. Around 1910 he writes up a method that solves such systems in about half the work of elimination, by taking square roots. He never publishes it. Cholesky is mortally wounded in battle in the last summer of the First World War and dies on 31 August 1918. In 1924 a fellow officer, Commandant Benoît, publishes the method in the Bulletin géodésique under Cholesky's name. A century later, it is how almost every finite-element code factorises a stiffness matrix.
A matrix is symmetric positive definite (SPD) if A=ATA = A^{\mathsf T} and xTAx>0\mathbf x^{\mathsf T}A\mathbf x > 0 for every nonzero x\mathbf x. That second condition sounds abstract. In engineering it is usually energy:
  • for a structure, 12uTKu\tfrac12\mathbf u^{\mathsf T}K\mathbf u is the strain energy stored by displacements u\mathbf u — positive for any deformation of a properly supported structure;
  • for a resistor network, vTGv\mathbf v^{\mathsf T}G\mathbf v is the power dissipated;
  • for heat conduction, it is the integral of ∣∇T∣2|\nabla T|^2.
Remove the supports and the structure can move as a rigid body with zero energy: KK becomes only semi-definite and singular. Positive definiteness is the matrix form of 'the structure is stable'.
💡Cholesky factorisation
Every SPD matrix can be written uniquely as A=LLTA = LL^{\mathsf T} with LL lower triangular and positive diagonal. Column by column: ljj=ajj−∑k<jljk2,lij=1ljj(aij−∑k<jlikljk), i>j.l_{jj} = \sqrt{a_{jj} - \textstyle\sum_{k<j} l_{jk}^2}, \qquad l_{ij} = \dfrac{1}{l_{jj}}\Big(a_{ij} - \textstyle\sum_{k<j} l_{ik}l_{jk}\Big),\ i > j. Symmetry means only half the matrix is stored and computed: 13n3\tfrac13 n^3 operations, half of LU. Positive definiteness guarantees the quantity under every square root is positive and that no pivoting is needed — Cholesky is backward stable as it stands. And if a square root of a negative number appears, the matrix was not positive definite: Cholesky doubles as the cheapest test for it.
Derivation
Cholesky's formulas, by matching entries
The 2×22 \times 2 case. Write out the product and match it with AA entry by entry:
[abbc]=[l110l21l22][l11l210l22]=[l112l11l21l11l21l212+l222].\begin{bmatrix} a & b \\ b & c \end{bmatrix} = \begin{bmatrix} l_{11} & 0 \\ l_{21} & l_{22} \end{bmatrix}\begin{bmatrix} l_{11} & l_{21} \\ 0 & l_{22} \end{bmatrix} = \begin{bmatrix} l_{11}^2 & l_{11}l_{21} \\ l_{11}l_{21} & l_{21}^2 + l_{22}^2 \end{bmatrix}.
Top left: l11=al_{11} = \sqrt a. Off diagonal: l21=b/al_{21} = b/\sqrt a. Bottom right: l22=c−b2/al_{22} = \sqrt{c - b^2/a}. The last square root is real exactly when ac−b2>0ac - b^2 > 0 — when the determinant is positive, which positive definiteness guarantees. When a quantity under a root comes out exactly zero — as it will for the springs below once their support is removed — the matrix is singular.
The general case. Entry (i,j)(i, j) of LLTLL^{\mathsf T} is row ii of LL times row jj of LL: ∑klikljk\sum_k l_{ik}l_{jk}, and since both rows end at their diagonal the sum stops at k=jk = j when i≥ji \ge j. Split off the last term:
aij=∑k<jlikljk+lij ljj.a_{ij} = \sum_{k<j} l_{ik}l_{jk} + l_{ij}\,l_{jj}.
For i=ji = j this is ajj=∑k<jljk2+ljj2a_{jj} = \sum_{k<j} l_{jk}^2 + l_{jj}^2, which gives ljjl_{jj}; for i>ji > j it gives lijl_{ij} — the two formulas above. Working column by column, everything on the right is already known. The quantity under each square root equals the pivot that Gaussian elimination would produce, and for an SPD matrix every pivot is positive (each leading block has positive determinant, the product of the pivots so far).
📐Three springs
Springs of 150, 150 and 100 kN/m in series, fixed at one end, 5 kN at the free end. The stiffness matrix and its Cholesky factor are K=[300−1500−150250−1000−100100],L=[17.3200−8.66013.2300−7.5596.547].K = \begin{bmatrix} 300 & -150 & 0 \\ -150 & 250 & -100 \\ 0 & -100 & 100 \end{bmatrix}, \qquad L = \begin{bmatrix} 17.32 & 0 & 0 \\ -8.660 & 13.23 & 0 \\ 0 & -7.559 & 6.547 \end{bmatrix}. Forward and back substitution give displacements 0.0333, 0.0667 and 0.1167 m — just 5/1505/150, then +5/150+5/150, then +5/100+5/100, as springs in series must. Remove the support (set K11=150K_{11} = 150) and the third pivot becomes exactly zero: the structure is a mechanism.
It is not knowledge, but the act of learning, not possession but the act of getting there, which grants the greatest enjoyment.
– Carl Friedrich Gauss, letter to Farkas Bolyai (1808)
Bandwidth. Number the unknowns along a rod and each one is coupled only to its neighbours: aij=0a_{ij} = 0 whenever ∣i−j∣>w|i - j| > w, the half-bandwidth. The key fact:
In Gaussian elimination or Cholesky without pivoting, the factors stay inside the band. Zeros outside the band are never touched.
So only the band needs to be stored — n(2w+1)n(2w+1) numbers, or n(w+1)n(w+1) for a symmetric matrix — and the work drops from 13n3\tfrac13 n^3 to about nw2n w^2. For the beam below, w=2w = 2: the work is proportional to nn, not n3n^3. scipy.linalg.solve_banded and cholesky_banded take matrices in exactly this compressed form.
Derivation
Why elimination never leaves the band
At stage kk, row rr is changed only if it has a nonzero in column kk below the pivot, which in a band means k<r≤k+wk < r \le k + w. The change subtracts a multiple of row kk, whose nonzeros lie in columns kk to k+wk + w. So row rr can only gain nonzeros in columns ≤k+w\le k + w, and k+w<r+wk + w < r + w: inside the band on the right. On the left, columns before kk have already been cleared in both rows. Nothing can appear outside ∣i−j∣≤w|i - j| \le w.
The work follows: at each of the nn stages, at most ww rows are updated in at most w+1w + 1 columns, about 2w22w^2 operations, so a banded LU costs about 2nw22nw^2 and banded Cholesky, using symmetry, about nw2nw^2 — instead of 23n3\tfrac23 n^3 and 13n3\tfrac13 n^3.
💡The Thomas algorithm
For a tridiagonal system (w=1w = 1) with sub-diagonal aia_i, diagonal bib_i, super-diagonal cic_i, elimination reduces to two short sweeps: forward:   ci′=cibi−aici−1′,di′=di−aidi−1′bi−aici−1′\;c'_i = \dfrac{c_i}{b_i - a_i c'_{i-1}}, \quad d'_i = \dfrac{d_i - a_i d'_{i-1}}{b_i - a_i c'_{i-1}} backward:   xn=dn′,xi=di′−ci′ xi+1\;x_n = d'_n, \quad x_i = d'_i - c'_i\,x_{i+1} About 8n8n operations and 4n4n numbers of storage. It is stable without pivoting when the matrix is diagonally dominant or SPD — which the matrices of heat conduction, diffusion and cubic splines always are. Llewellyn Thomas described it in 1949.
Derivation
The Thomas algorithm is elimination, written for three diagonals
Row ii of the system reads aixi−1+bixi+cixi+1=dia_ix_{i-1} + b_ix_i + c_ix_{i+1} = d_i (with a1=0a_1 = 0 and cn=0c_n = 0).
Row 1. Divide by b1b_1: x1+c1′x2=d1′x_1 + c'_1x_2 = d'_1, with c1′=c1/b1c'_1 = c_1/b_1 and d1′=d1/b1d'_1 = d_1/b_1.
Row ii. Suppose the row above has already been reduced to xi−1+ci−1′xi=di−1′x_{i-1} + c'_{i-1}x_i = d'_{i-1}. Use it to eliminate xi−1x_{i-1}: substitute xi−1=di−1′−ci−1′xix_{i-1} = d'_{i-1} - c'_{i-1}x_i into row ii,
ai(di−1′−ci−1′xi)+bixi+cixi+1=di⟹(bi−aici−1′) xi+cixi+1=di−aidi−1′,a_i\big(d'_{i-1} - c'_{i-1}x_i\big) + b_ix_i + c_ix_{i+1} = d_i \quad\Longrightarrow\quad (b_i - a_ic'_{i-1})\,x_i + c_ix_{i+1} = d_i - a_id'_{i-1},
and divide by bi−aici−1′b_i - a_ic'_{i-1}. The result has the same two-term form, xi+ci′xi+1=di′x_i + c'_ix_{i+1} = d'_i, with exactly the forward-sweep formulas above.
Back substitution. The last row has no xn+1x_{n+1}, so xn=dn′x_n = d'_n; each earlier row then gives xi=di′−ci′xi+1x_i = d'_i - c'_ix_{i+1}. Every row costs a handful of operations: O(n)O(n) in total. Diagonal dominance keeps each divisor bi−aici−1′b_i - a_ic'_{i-1} away from zero, which is why no pivoting is needed.
Derivation
The second-difference stencil, from Taylor's theorem
Lesson 1-3 built first-derivative formulas by subtracting the expansions of u(x+h)u(x + h) and u(x−h)u(x - h). Adding them instead cancels every odd derivative:
u(x+h)+u(x−h)=2u(x)+h2u′′(x)+h412u′′′′(x)+…u(x + h) + u(x - h) = 2u(x) + h^2u''(x) + \frac{h^4}{12}u''''(x) + \dots
Solve for u′′u'':
u′′(x)=u(x−h)−2u(x)+u(x+h)h2−h212u′′′′(x)−…u''(x) = \frac{u(x - h) - 2u(x) + u(x + h)}{h^2} - \frac{h^2}{12}u''''(x) - \dots
So −u′′≈(−ui−1+2ui−ui+1)/h2-u'' \approx (-u_{i-1} + 2u_i - u_{i+1})/h^2 — the rows (−1, 2, −1)/h2(-1,\ 2,\ -1)/h^2 of the matrix below — with a truncation error proportional to h2h^2. Each equation involves a point and its two neighbours, and that is the whole reason the matrix is tridiagonal.
Applying it twice gives the fourth derivative of the beam equation. The second difference of the second differences has weights (1,−2,1)(1, -2, 1) combined with (1,−2,1)(1, -2, 1):
ui′′′′≈ui−2−4ui−1+6ui−4ui+1+ui+2h4,u''''_i \approx \frac{u_{i-2} - 4u_{i-1} + 6u_i - 4u_{i+1} + u_{i+2}}{h^4},
five diagonals: 1⋅11 \cdot 1, then 1⋅(−2)+(−2)⋅1=−41 \cdot (-2) + (-2) \cdot 1 = -4, then 1+4+1=61 + 4 + 1 = 6, and symmetrically.
📐Heat in a rod, and a beam
Steady conduction with internal heating, −u′′=f-u'' = f on [0,1][0, 1], discretised with central differences on nn interior points, gives the tridiagonal system with rows (−1, 2, −1)/h2(-1,\ 2,\ -1)/h^2. With f=π2sin⁡πxf = \pi^2\sin\pi x the exact answer is sin⁡πx\sin\pi x, and the Thomas algorithm gives maximum errors 8.1×10−58.1 \times 10^{-5}, 8.2×10−78.2 \times 10^{-7} and 8.2×10−98.2 \times 10^{-9} for n=100,1000,10 000n = 100, 1000, 10\,000: the O(h2)O(h^2) of lesson 1-3, at a cost proportional to nn. Stored densely, n=100 000n = 100\,000 would need 80 GB; as three diagonals, 2.4 MB. A simply supported beam, EI w′′′′=qEI\,w'''' = q, gives five diagonals (1,−4,6,−4,1)/h4(1, -4, 6, -4, 1)/h^4. For L=10L = 10 m, EI=2×107EI = 2 \times 10^7 N m², q=10q = 10 kN/m, the banded solver's midspan deflection converges to 65.1042 mm — exactly the textbook 5qL4/(384EI)5qL^4/(384EI).
⚠When the band is not enough
Number a 2-D plate's grid row by row and each node is coupled to the node one full row away: the half-bandwidth is the number of nodes per row, mm, and the band is mostly holes. Cholesky fills those holes — every zero inside the band becomes a nonzero in LL, called fill-in. For m2m^2 unknowns that is about m3m^3 entries in LL and m4m^4 operations: far better than dense, far worse than the five nonzeros per row the matrix actually has.
💡Where you will use this
Structures and Geotechnics: stiffness matrices are SPD and banded; skyline and banded Cholesky solvers ran the first generations of finite-element software. Hydraulic and Thermal engineering: implicit time steps for 1-D diffusion and open-channel flow are tridiagonal, solved by Thomas at every step. Attitude Control and Navigation: Kalman filters keep covariance matrices as Cholesky factors ('square-root filters') so they stay positive definite in finite precision. Interpolation: cubic splines (Unit 7) solve a tridiagonal system.
📚Further reading
  • Gene Golub and Charles Van Loan, Matrix Computations (4th ed., Johns Hopkins, 2013), chapter 4, 'Special Linear Systems' — Cholesky, banded and tridiagonal solvers.
  • Lloyd N. Trefethen and David Bau, Numerical Linear Algebra (SIAM, 1997), Lecture 23, 'Cholesky Factorization'.
  • Randall LeVeque, Finite Difference Methods for Ordinary and Partial Differential Equations (SIAM, 2007), chapter 2 — the second-difference matrix of a two-point boundary value problem, its accuracy and its stability.
↓But there is a problem
Banded solvers rescue 1-D problems completely. In 2-D and 3-D the band is wide and full of holes, and fill-in eats most of the savings. In 1956 four engineers at Boeing — M. J. Turner, R. W. Clough, H. C. Martin and L. J. Topp — needed the stiffness of a swept delta wing. They broke it into small triangular panels, wrote a stiffness matrix for each, and assembled them into one huge system. The method became the finite element method. Its matrices have millions of rows and only a handful of nonzeros in each — and the order in which you number the unknowns decides whether it can be solved at all.