伪-高斯消元法
由于本人太弱 , 看不懂高斯消元 , 自已
小学老师和我们说过加减法可以消元。
然后我就加减法。没了。
对于一个方程 :
我们把它用行列式存起来 :
我们从后往前选择主元 , 进行 系数化一。然后进行 上下相减的操作 。以下用小数表示 :
首先
接着我们加减消元 , 留下两个方程:
如法炮制 :
上下相减 :
这个时候我们就得到了 :
考虑回带 ? 很麻烦 ?
不是 , 我们每次操作的时候 留下一个当前的方程 , 比如做完的时候矩阵变成这样 :
这样子回带就非常的短啦 !
加减得出 :
Const
total=100+10;
var
num:array[-1..total,-1..total] of extended;
ans,resu:array[-1..total] of extended;
i,j,n:longint;
procedure No_Solution; begin writeln('No Solution'); halt; end;
procedure Gauss(x:longint);
var
sum:extended;
i:longint;
begin
if x=1 then begin if num[1,1]=0 then No_Solution; ans[1]:=resu[1]/num[1,1]; exit; end;
for i:=1 to x do
begin
if num[i,x]=0 then continue; resu[i]:=resu[i]/num[i,x];
for j:=1 to x do num[i,j]:=num[i,j]/num[i,x];
end;
for i:=1 to x-1 do begin for j:=1 to x-1 do num[i,j]:=num[i,j]-num[i+1,j]; resu[i]:=resu[i]-resu[i+1]; end;
Gauss(x-1); sum:=0; for i:=1 to x-1 do sum:=sum+num[x,i]*ans[i];
if num[x,x]=0 then No_Solution; ans[x]:=(resu[x]-sum)/num[x,x];
end;
begin
read(n); if n=0 then No_Solution;
for i:=1 to n do begin for j:=1 to n do read(num[i,j]); read(resu[i]); end;
Gauss(n); for i:=1 to n do writeln(ans[i]:0:2);
end.