Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %Cholesky decomposition
- A = [44 15 29 26 119;15 33 22 18 15;29 32 252 112 73;26 18 112 124 90; 119 15 73 90 430];
- eigenvals = eig(A);
- if all(A>0)
- disp("Matrix A is spd!")
- end
- H1 = chol(A)';
- H2 = MyChol(A);
- disp(H1);
- disp(H2);
- disp(isequal(H1,H2));
- function[H]=MyChol(A)
- dimension = size(A);
- H = zeros(dimension(1),dimension(1));
- H(1,1) = sqrt(A(1,1));
- for i=2:dimension(1)
- for j=1:i-1
- tempsum = 0;
- for k=1:j-1
- tempsum = tempsum + H(i,k)*H(j,k);
- end
- H(i,j) = (A(i,j)-tempsum)/H(j,j);
- end
- rowsum = 0;
- for k=1:i-1
- rowsum = rowsum + H(i,k)^2;
- end
- H(i,i) = sqrt(A(i,i)-rowsum);
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement