裸的高斯消元不多说

 1 var a:array[0..12,0..12] of double;
 2     b:array[0..12] of double;
 3     p,i,j,k,n:longint;
 4     x:double;
 5 
 6 procedure swap(var a,b:double);
 7   var c:double;
 8   begin
 9     c:=a;
10     a:=b;
11     b:=c;
12   end;
13 
14 procedure gauss;
15   begin
16     for i:=1 to n do
17     begin
18       p:=i;
19       for j:=i to n do
20         if abs(a[p,i])<abs(a[j,i]) then p:=j;
21       if p<>i then
22       begin
23         for j:=1 to n+1 do
24           swap(a[p,j],a[i,j]);
25       end;
26       for j:=i+1 to n do
27         if a[j,i]<>0 then
28         begin
29           for k:=n+1 downto i do
30             a[j,k]:=a[j,k]-a[i,k]*a[j,i]/a[i,i];
31         end;
32     end;
33     for i:=n downto 1 do
34     begin
35       for j:=i+1 to n do
36         a[i,n+1]:=a[i,n+1]-a[j,n+1]*a[i,j];
37       a[i,n+1]:=a[i,n+1]/a[i,i];
38     end;
39   end;
40 
41 begin
42   readln(n);
43   for i:=1 to n do
44     read(b[i]);
45   for i:=1 to n do
46   begin
47     for j:=1 to n do
48     begin
49       read(x);
50       a[i,j]:=(x-b[j])*2;
51       a[i,n+1]:=a[i,n+1]+sqr(x)-sqr(b[j]);
52     end;
53   end;
54   gauss;
55   for i:=1 to n do
56   begin
57     write(a[i,n+1]:0:3);
58     if i<>n then write(' ');
59   end;
60   writeln;
61 end.
View Code

 

posted on 2014-09-19 22:39  acphile  阅读(128)  评论(0编辑  收藏  举报