📄 gaosi.m
字号:
function y=gaosi(a)
%高斯消去法求逆阵
%a=需要求逆的矩阵,y为结果
row=size(a,1);
num=size(a,2);
if row~=num
'你输入的矩阵不可逆'
break;
end
tempM=eye(row);
tempM=[a,tempM];
for k=1:row
%列主元素法将矩阵进行一定的预先排序处理
j=k;
tempN=tempM(k,k);
for kk=k:row
tempN=tempM(k,k);
if tempM(kk,k)>tempN
j=kk;
tempN=tempM(kk,k);
end
end
%tempN=tempM(j,:);
%tempM(j,:)=tempM(k,:);
%tempM(k,:)=tempN;
tempM([k,j],:)=tempM([j,k],:);
%消去为上三角的过程
for i=k:row
if i==k
tempM(i,:)=tempM(i,:)/tempM(k,k);
else
tempM(i,:)=tempM(i,:)-tempM(k,:)*tempM(i,k)
end
end
end
%以下是回代过程
for k=row:-1:1
for i=k:-1:1
if i~=k
tempM(i,:)=tempM(i,:)-tempM(k,:)*tempM(i,k)
end
end
end
tempM=tempM(:,[(row+1):2*row]);
y=tempM;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -