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
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
by