基于MATLAB的Cholesky分解法

时间:2021-01-26 05:52:07

Method


Let L = [ l 11 0   0 l 21 l 22   0 l n 1 l n 2   l n n ]
Use Squre Root Method, when A = L L T , we have:

u i i = a i i k = 1 i 1 u k i 2 , i = 1 , , n

u i j = a i j k = 1 i 1 u i k u j k u i i , j = i + 1 , , n

Using these two function to realize Cholesky factorization.

function [L]=Cholesky(A) %平方根法
    [N,N]=size(A);
    X=zeros(N,1);
    Y=zeros(N,1);
    for i=1:N
        A(i,i)=sqrt(A(i,i)-A(i,1:i-1)*A(i,1:i-1)'); if A(i,i)==0 'A is singular, no unique solution';
            break;
        end
        for j=i+1:N
            A(j,i)=(A(j,i)-A(j,1:i-1)*A(i,1:i-1)')/A(i,i); end end for x=1:N for y=1:N B(x,y)=A(x,y); %右上角元素归0 if x<y B(x,y)=0; break; end end end L=B