0% found this document useful (0 votes)
37 views2 pages

Cholesky Decomposition: Switch Case

This document describes the Cholesky decomposition method for solving systems of linear equations and finding the inverse of a matrix. It provides a menu that allows the user to choose between these two applications. It then uses a Cholesky decomposition function to decompose the input matrix into a lower triangular matrix before solving the system of equations or calculating the inverse. The Cholesky decomposition function decomposes the symmetric positive definite input matrix into a lower triangular matrix.

Uploaded by

Kuldeep Ratnu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views2 pages

Cholesky Decomposition: Switch Case

This document describes the Cholesky decomposition method for solving systems of linear equations and finding the inverse of a matrix. It provides a menu that allows the user to choose between these two applications. It then uses a Cholesky decomposition function to decompose the input matrix into a lower triangular matrix before solving the system of equations or calculating the inverse. The Cholesky decomposition function decomposes the symmetric positive definite input matrix into a lower triangular matrix.

Uploaded by

Kuldeep Ratnu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Cholesky decomposition

disp('***************************MAIN
MENU*************************');
disp('Applications of Cholesky Decomposition');
disp('1. Solve a system of linear equations');
disp('2. Find inverse of a matrix');
choice=input('Enter your choice:');
switch choice
case 1
A=input('Enter matrix A:');
L=cholesky2(A)
b=input('Enter matrix B:');
z=L\b;
Forward substitution
disp('Solution Vector')
x=L'\z
Backward substitution
case 2
A=input('Enter matrix A:');
L=cholesky2(A)
disp('Inverse of A :')
Ainv= inv(L')*inv(L)
otherwise
disp('Wrong Choice!!')
return;
end
%*************END of the Program *******************

%
%

function [ L ] = cholesky2( A )
[m,n]=size(A);
if m~=n
disp('Matrix shoud be a square matrix');
elseif A~=A'
fprintf('Given matrix is not symmetric. \n Cholesky Method
doesnot apply to asymmetric matrices!\n');
elseif length(find(eig(A)>0))~=length(eig(A))
fprintf('Given matrix is not positive definite. \n Cholesky
Method doesnot apply to non-positive definite matrices!\n');
else
L = zeros( n, n );
for j=1:n
for i=j:n
sum=0;
if i==j
for k=1 : j-1
sum = sum + L(j,k)^2;
end
L(j,j)=sqrt(A(j,j)-sum);
else

end
end

end

for k=1 : j-1


sum = sum + L(i,k)*L(j,k);
end
L(i,j)=(A(i,j)- sum)/L(j,j);
end
end

output:
METHOD 2function A=Cholesky(A)
% Cholesky Factorization for symmetric positive definite matrix

% Factorize A such that A = L*L',


% where L is a lower triangular matrix whose diagonal entries are not
% necessarily unity
[n nn]=size(A);
for k=1:n
A(k,k)=sqrt(A(k,k));
A(k+1:n,k)=A(k+1:n,k)/A(k,k);
for j=k+1:n
A(j:n,j)=A(j:n,j)-A(j,k)*A(j:n,k);
end
end

You might also like