%% Cholesky Factorization of Matrix
% Calculate the upper and lower Cholesky factorizations of a matrix and verify the results.
%
% Create a 6-by-6 symmetric positive definite test matrix using the gallery function.

A = gallery('lehmer',6);

%
% Calculate the Cholesky factor using the upper triangle of A.

R = chol(A)

%
% Verify that the upper triangular factor satisfies R'*R - A = 0, within roundoff error.

norm(R'*R - A)

%
% Now, specify the 'lower' option to calculate the Cholesky factor using the lower triangle of A.

L = chol(A,'lower')

%
% Verify that the lower triangular factor satisfies L*L' - A = 0, within roundoff error.

norm(L*L' - A)

%
% Copyright 2018 The MathWorks, Inc.