%% Solve Linear System with Symmetric Positive Definite Matrix
% Use chol to factorize a symmetric coefficient matrix, and then solve a linear system using the Cholesky factor.
%
% Create a symmetric matrix with positive values on the diagonal.

A = [1 0 1; 0 2 0; 1 0 3]

%
% Calculate the Cholesky factor of the matrix.

R = chol(A)

%
% Create a vector for the right-hand side of the equation \textrm{Ax}=b.

b = sum(A,2);

%
% Since A=R^T R with the Cholesky decomposition, the linear equation becomes R^T R\;x=b. Solve for x using the backslash operator.

x = R\(R'\b)

%
% Copyright 2018 The MathWorks, Inc.