Clear Filters
Clear Filters

Understanding a Cholesky Factorisation Algorithim

2 views (last 30 days)
Hello I am reviewing the following code for Cholesky Factorisation, trying to understand each individual step. I am new to Matlab and have tested the code (it does work). At the step which I've marked by %***%, I believe that the value produced by multiplying matrix elements L(j,k)*L(i,k) will always be zero, in particular, the element L(j,k) will always be zero since the matrix element L is 0 before the for loop and it is not redefined at the end of the for loop, and iterated k=j-1 times. I.e s=s at this step in the code and always will be.
Is there perhaps a visualisation or an effective way to understand how the elements of this code work? I have tried running the simulation by hand and it gets very large and complicated very quickly.
function L = CholScalar(A)
% L = CholScalar(A)
% Cholesky factorization of a symmetric and positive definite matrix A.
% L is lower triangular so A = L*L'.
[n,n] = size(A);
L = zeros(n,n);
for i=1:n
% Compute L(i,1:i)
for j=1:i
s = A(j,i);
for k=1:j-1 %****% This is the step I don't understand.
s = s - L(j,k)*L(i,k);
end
if j<i
L(i,j) = s/L(j,j);
else
L(i,i) = sqrt(s);
end
end
end

Answers (1)

James Tursa
James Tursa on 24 Sep 2018
To see if your supposition is correct, just add this to your for loop and put a break point there:
for k=1:j-1 %****% This is the step I don't understand.
s = s - L(j,k)*L(i,k);
if( L(j,k) ~= 0 )
disp('not zero'); % <-- break point here
end
end
Then run your code.

Categories

Find more on Elementary Math in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!