Every positive number a has a square root: a=a⋅a. A positive definite matrix has a matrix version of this, built from a lower triangular matrix: one with only zeros above the diagonal.
Take
A=(4225),L=(2102)L⊤=(2012)
Multiply L by its transpose, row by column (lesson 3.2.1):
entry of LL⊤
row of L · column of L⊤
value
(1,1)
(2,0)⋅(2,0)
4
(1,2) and (2,1)
(2,0)⋅(1,2)
2
(2,2)
(1,2)⋅(1,2)
5
So LL⊤=A. The two off-diagonal entries are equal because LL⊤ is always symmetric: (LL⊤)⊤=LL⊤ by the rule of lesson 3.2.3.
Rule: The Cholesky factorisation
A=LL⊤L lower triangular, lii>0
A symmetric matrix A has such an L exactly when it is positive definite, and then L is unique. L is the Cholesky factor of A, named after André-Louis Cholesky.
It is the completed square. Lesson 3.7.1 wrote a quadratic form as a sum of squares. With A=LL⊤,
x⊤Ax=(L⊤x)⊤(L⊤x)=∥L⊤x∥2
Here L⊤x=(2x1+x2,2x2), so 4x12+4x1x2+5x22=(2x1+x2)2+(2x2)2. That is lesson 3.7.1's a(x1+abx2)2+aac−b2x22=4(x1+21x2)2+4x22, written with a matrix. At (1,−1) both sides give 5.
The order matters: L⊤L=(5224), which is not A.
Try it
The first two lines multiply LL⊤ and L⊤L: only the first gives A.
The last line evaluates the form at x=(1,−1) twice: as x⊤Ax, and as the squared length of L⊤x=(1,−2).
⌘/Ctrl + Enter runs the cell
The 2 × 2 formulas
Write L=(l11l210l22) and multiply out:
LL⊤=(l112l11l21l11l21l212+l222)
Match this with A=(abbc), one entry at a time: l112=a first, then l11l21=b, then l212+l222=c.
Rule: Cholesky for 2 × 2
l11=a,l21=l11bl22=c−l212
Each step uses only what came before. The number under the last square root is c−ab2=aac−b2, so both roots are real and positive exactly when a>0 and ac−b2>0: lesson 3.7.1's leading-minor test.
Three examples:
A
l11
l21
l22
(4225)
4=2
2÷2=1
5−1=2
(10.60.61)
1
0.6
1−0.36=0.8
(3112)
3≈1.7321
31≈0.5774
5/3≈1.291
The second row has 1 on its diagonal and ρ=0.6 off it. For any such matrix, L=(1ρ01−ρ2).
When it fails. For lesson 3.7.1's indefinite N=(1221), l11=1 and l21=2, and l22 would be 1−4=−3: no real number. For the semidefinite J=(1111), l22=1−1=0, which is not positive, and L has no inverse.
Try it
chol2 is the rule. For each example it prints L to 4 places and checks LL⊤=A.
The last line is what l22 would be the square root of for N: −3.
⌘/Ctrl + Enter runs the cell
A 3 × 3 example by hand
For larger matrices, match LL⊤=A one column of L at a time, from left to right. Each diagonal entry is a square root, and each entry below it a division.
Rule: Cholesky, column j
ljj=ajj−∑k<jljk2lij=ljjaij−∑k<jlikljkfor each i>j
The sums run over the columns already found, to the left of column j; for j=1 they are empty. If a number under a square root is 0 or negative, A is not positive definite and the method stops.
Factor
A=42−22102−226
step
entry
working
value
1
l11
4
2
2
l21
2÷2
1
3
l31
−2÷2
−1
4
l22
10−12
3
5
l32
(2−(−1)(1))÷3
1
6
l33
6−(−1)2−12
2
L=21−1031002
Check one entry: row 3 of L dotted with row 2 of L is (−1)(1)+(1)(3)+(2)(0)=2=a32.
The link with elimination. Eliminate on A as in lesson 3.3.1, with no row swaps: R2−21R1, R3+21R1, then R3−31R2. The pivots are 4, 9 and 4, the squares of L's diagonal.
A symmetric matrix is positive definite exactly when elimination without swaps gives all positive pivots. Since detA is the product of the pivots (lesson 3.4.1), detA=(2⋅3⋅2)2=144.
Cholesky does about half the arithmetic of elimination, because A's symmetry means only one triangle needs computing. For a positive definite matrix it also needs no row swaps.
Try it
cholesky is the rule, column by column. L[j, :j] is the part of row j to the left of the diagonal. So L[j, :j] @ L[j, :j] is the sum of its squares.
It agrees with np.linalg.cholesky. The last line gives detA and the squared product of L's diagonal.
⌘/Ctrl + Enter runs the cell
Try it
The three row operations of the text, without swaps. The diagonal of U holds the pivots, and their square roots are L's diagonal.
⌘/Ctrl + Enter runs the cell
In NumPy: a test for positive definiteness
np.linalg.cholesky(A) returns L. When A is not positive definite it stops with LinAlgError: Matrix is not positive definite, as inv stopped on a singular matrix in lesson 3.2.3.
That makes it the quickest test on a computer: try the factorisation and catch the error. It costs less than finding the eigenvalues. It fails for the indefinite N and for the semidefinite J.
Rule: Cholesky as a test
the factorisation succeeds⟺A is positive definite
The equivalence holds for symmetric A, so check symmetry first. A failure says only "not positive definite": the eigenvalues tell whether A is indefinite or semidefinite.
Two traps in the code:
NumPy does not check symmetry. It reads only the lower triangle and the diagonal. (421005) returns the same L as A, with no warning. Test np.allclose(A, A.T) before factoring.
SciPy returns the other triangle.scipy.linalg.cholesky(A) returns the upper factor L⊤ unless you pass lower=True.
A semidefinite matrix sits on the edge. For J the last step is exactly 0, so the test fails. When rounding is involved, a zero can come out as a tiny positive number, and the factorisation may succeed with a useless, near-zero diagonal entry.
Try it
cholesky returns L for A and raises LinAlgError for N and J. The typo matrix is not symmetric, yet it returns A's L. SciPy gives L⊤.
is_positive_definite checks symmetry first, then tries the factorisation. The last matrix is lesson 3.7.1's K.
⌘/Ctrl + Enter runs the cell
Solving Ax = b with two triangular solves
With A=LL⊤, the system Ax=b is L(L⊤x)=b. Call the bracket y and solve in two steps, each with a triangular matrix.
Rule: Solving with Cholesky
Ly=b(forward)L⊤x=y(back)
Forward substitution solves Ly=b from the top: row 1 of L has one unknown, and each row below adds one more. Back substitution (lesson 3.3.1) then solves L⊤x=y from the bottom.
Solve Ax=(−2,−4,8) with the 3×3 example. Forward, with the rows of L, (2,0,0), (1,3,0) and (−1,1,2):
y1y2y3=−2÷2=−1=(−4−y1)÷3=−1=(8+y1−y2)÷2=4
Back, with L⊤=200130−112:
x3x2x1=4÷2=2=(−1−x3)÷3=−1=(−1−x2+x3)÷2=1
So x=(1,−1,2). Check it in row 3 of A: −2(1)+2(−1)+6(2)=8.
Factoring is the expensive part. Once L is known, each new right-hand side b costs only the two triangular solves, far less than a new elimination.
Try it
solve_triangular from SciPy does each step; lower=True says the matrix is lower triangular. The answer agrees with np.linalg.solve.
The last lines are the forward substitution written out, as in the text.
⌘/Ctrl + Enter runs the cell
L as a square root
A=LL⊤ is the matrix version of a=a⋅a. For a 1×1 matrix (a), L=(a). For a diagonal matrix, L takes the square root of each diagonal entry: (0.04000.09) gives L=(0.2000.3).
And detA=(detL)2, with detL the product of L's diagonal.
As a map, L sends the unit circle to an ellipse, as lesson 3.6.3 found for symmetric matrices. Its first column Le1=(2,1) and its second Le2=(0,2) both land on that ellipse. Le2 points straight up, because the first row of L is (2,0).
L is not the only square root. Lesson 3.6.3 writes A=QΛQ⊤. Taking Λ1/2, the diagonal matrix of λi, gives the symmetric square rootB=QΛ1/2Q⊤, with BB⊤=A too. For A above, B≈(1.94030.48510.48512.1828).
L and B send the unit circle to the same ellipse, because LL⊤=BB⊤=A, though each point lands somewhere different. Its semi-axes are λ for the eigenvalues of A: about 2.56 and 1.56.
Any C with CC⊤=A gives that ellipse. Cholesky picks the one that is lower triangular with a positive diagonal, which is the cheapest to compute and to solve with. Case study 3.7.4 uses L to turn independent random numbers into correlated ones, with a covariance matrix as A.
Try it
B is built from eigh, as in lesson 3.6.3. Both B and L multiply with their transposes to give A.
Then the eigenvalues of A and their square roots, the ellipse's semi-axes. The last lines are the diagonal example and detL=4, detA=16.
⌘/Ctrl + Enter runs the cell
Common mistakes
LL⊤, not L⊤L. For L=(2102), L⊤L=(5224), not A.
Take the square root on the diagonal.l11=a11, not a11.
Below the diagonal, divide by the diagonal entry of the same column,ljj, after subtracting the products already found.
Check symmetry first.np.linalg.cholesky reads only the lower triangle and never complains about the upper one.
Know which triangle you get. NumPy returns L; scipy.linalg.cholesky returns L⊤ unless lower=True.
Forward first, then back. Solve Ly=b from the top, then L⊤x=y from the bottom.
A failure means "not positive definite", nothing more. The matrix may be indefinite, or semidefinite with a zero eigenvalue; ask eigvalsh which.
The Cholesky factorisation
0 of 12 correct
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
How to type answers
Powers with ^: x^7, 2^(1/3), a^-2.
Multiply with * or by writing side by side: 3x^2, 2(x+1).
ln(x) is the natural log, log(x, 2) is log base 2, e is Euler's number, sqrt(x) is a square root.
sin(x), cos(x) and tan(x) take radians; write pi for π and sin(x)^2 for sin²x.
Your first answer to each question is saved: it counts towards your score and brings the question back for review.
Exact answers like ln(20)/ln(3) are best. Decimals need about 4 significant figures.
Summary card
A positive definite A has exactly one Cholesky factor: A=LL⊤ with L lower triangular and a positive diagonal. Then x⊤Ax=∥L⊤x∥2, the completed square.
2×2: l11=a, l21=b/l11, l22=c−l212. In general, column by column: ljj=ajj−∑k<jljk2 and lij=(aij−∑k<jlikljk)/ljj.
The diagonal of L holds the square roots of the pivots, and detA=(detL)2.
np.linalg.cholesky raises LinAlgError exactly when a symmetric A is not positive definite: the cheapest test. It reads only the lower triangle, so check symmetry first.
Solve Ax=b by forward substitution in Ly=b, then back substitution in L⊤x=y.
L is one square root of A; the symmetric QΛ1/2Q⊤ is another, mapping the unit circle to the same ellipse.