Celeb Glow
news | April 08, 2026

How to solve a matrix using Cholesky Decompositon on Matlab

$\begingroup$

I'm trying to solve a system of linear equations on MATLAB, I have written a code that solves the problem using Gaussian Elimination. But I was wondering how I could modify this to use other methods of matrix decomposition, such as Cholesky Decomposition?

%set up matrices
A=[-900 400 0 0 0; 500 -900 400 0 0; 0 500 -900 400 0; 0 0 500 -900 400; 0 0 0 400 -900];
b=[0;0;0;0;0];
%decompose A matrix
[L, U] = lu(A);
%set up series of yin's for plot
yin=0:0.01:0.25;
yout=zeros(length(yin),1);
xout=zeros(length(yin),1);
%create b based on yin, and solve
for i=1:1:length(yin) b(1)=-500*yin(i); d = L\b; y = U\d; %save yout and xout values before next iteration yout(i)=y(5); xout(i)=y(1)*4;
end
$\endgroup$

1 Answer

$\begingroup$

Given a self-adjoint positive-definite square matrix $A$, $\operatorname{chol}(A)$ returns an upper triangular matrix $U$ such that $A = U^* U$

To turn this into code, replace

[L, U] = lu(A);

by

U = chol(A);
L = U';
$\endgroup$

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy