📄 minvbygre.m
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -