6.7. Cholesky Decomposition for Positive Definite Systems¶
Systems of linear equations of the form
are often symmetric and positive
definite. Equations deriving from physical applications such as
electrical, mechanical, and structural systems are often positive
definite. We will see in Over-determined Systems and Vector Projections that the solutions to
over-determined systems, such as found with least squares regression
problems (Least Squares Regression), make use positive definite matrices of
the form
. The diagonal values of
are positive because each is the dot
product of a column of
with itself. Likewise, the
diagonal values of a positive definite matrix are always positive. The
special symmetry of positive definite matrices allows for a simple and
numerically accurate factoring called the Cholesky decomposition that
returns an upper triangular matrix,
. The transpose of
gives us a lower triangular matrix. The product of the
lower triangular matrix and upper triangular is the decomposition of
that we will use as we did with LU decomposition to find
the solution using a triangular solver.
(6.17)¶
The Cholesky decomposition can only be used for positive definite
matrices. A positive definite matrix is real,
symmetric, and satisfies the property
(6.18)¶
The left side of equation (6.18) reduces to a dot
product that yields a real, scalar number. Unfortunately, equation
(6.18) is a difficult test to apply because it
allows for an infinite set of vectors. An alternate
criteria for evaluating if a matrix is positive definite consists of
three tests.
- Is the matrix symmetric?
- Are all of the elements along the diagonal of the matrix positive?
- Are all of the eigenvalues of the matrix positive?
The procedure for finding the eigenvalues of a matrix is addressed in Application of Eigenvalues and Eigenvectors, but we will not use the third test. A faster final test to see if the Cholesky decomposition can be used is to attempt to use it. The decomposition fails if the algorithm needs to take the square root of a number that is zero or negative. So we can attempt to use the Cholesky decomposition algorithm if the matrix is symmetric and has only positive values along the diagonal. The decomposition function listed in
The cholesky
function below returns a boolean flag indicating if the
algorithm was able to complete the decomposition, which also tells us if
the matrix is positive definite or not.
The development of the Cholesky decomposition algorithm comes from the
algebra of how is computed as the product of
and
.
The first row is simple because each element of comes
from only one product.
(6.19)¶
In the subsequent rows, we find the value of the diagonal element using previous found values in the column of the diagonal element.
(6.20)¶
The algorithm uses equation (6.20) to check if the matrix still appears to be positive definite. If the argument to square root is zero or a negative number, then the algorithm is finished with the matrix marked as not being positive definite. The remaining values of each row are found after finding the diagonal element.
(6.21)¶
The cholesky
function uses equations (6.19) to
(6.21) to find the Cholesky decomposition. MATLAB has a
function called chol
that finds the same.
function [R, isPositiveDefinite] = cholesky(A)
% CHOLESKY decomposition. If A is posive definite, A = R'*R.
% isPositiveDefinite is a boolean variable. Use R only if
% isPositiveDefinite is true.
[m,n] = size(A);
if m ~= n
error("Matrix is not square")
elseif ~issymmetric(A)
error("Matrix is not positive definite or symmetric")
end
if any(diag(A<=0))
msg = "Matrix is not positive definite/n";
msg = strcat(msg, "Diagonal not all positive");
error(msg);
end
isPositiveDefinite = true;
for i = 1:n
for k = 1:i-1 % skip i = 1
A(i,i) = A(i,i) - A(k,i)^2;
end
if A(i,i) <= 0
isPositiveDefinite = false;
R = 0;
return;
end
A(i,i) = sqrt(A(i,i));
for j = i+1:n
for k = 1:i-1
A(i,j) = A(i,j) - A(k,i)*A(k,j);
end
A(i,j) = A(i,j)/A(i,i);
end
end
R = triu(A);