minvbygre.m

来自「用greville方法求逆矩阵」· M 代码 · 共 34 行

M
34
字号
function invA=minvbyGRE(A);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% *summary:caculate inverse matrix by GREVILLE method
% *input:
% A- should be square matrix
% *output:
% invA- the inverse
% *special data needed: no
% *function needed: no
% *author: Yao Zhenjie 
% *email: yaozhenjie@gmail.com
% *2008.1.10@Graduate University of Chinese Academy of Sciences
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[m,n]=size(A);
if m~=n
    error('this matrix is not a square matrix, we can not caculate its inverse')
end
if det(A)==0
    error('this matrix is sigular matrix, we can not caculate its inverse')
end
invA=zeros(m,n);
invA(1,:)=(1/(A(:,1)'*A(:,1)))*A(:,1)';
for i=2:m
    d=invA(1:i-1,:)*A(:,i);
    c=A(:,i)-A(:,1:i-1)*d;
    if all(c==0)
        b=(1/((1+d'*d)*d'))*invA(1:i-1,:);
    else
        b=(1/(c'*c))*c';
    end
    invA(1:i-1,:)=invA(1:i-1,:)-d*b;
    invA(i,:)=b;
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?