我的这段代码为什么不能通过呢?是sqrt的原因,还是loop超值了?
type TM=array of array of double;
TN=array of double;
procedure ACHOL(var A:TM
var n:integer
var D:TN);
var i,j,k:integer;
begin
setlength(A,n+1,n+1);setlength(D,n+1);
A[1,1]:=sqrt(A[1,1]);
for j:=2 to n do
begin A[1,j]:=A[1,j]/A[1,1]
end;
for i:=2 to n do
begin //10
for j:=2 to i do
begin A[i,i]:=A[i,i]-A[j-1,i]*A[j-1,i]
end;
A[i,i]:=sqrt(A[i,i])
if (i<>n) then
begin
for j:=i+1 to n do
for k:=2 to i do
A[i,j]:=A[i,j]-A[k-1,i]*A[k-1,j];
A[i,j]:=A[i,j]/A[i,i];
end;
end
//10
D[1]:=D[1]/A[1,1];
for i:=2 to n do begin
for k:=2 to i do
begin D:=D-A[k-1,i]*D[k-1]
end;
D:=D/A[i,i];
end;
D[n]:=D[n]/A[n,n];
for k:=n downto 2 do begin
for i:=k to n do begin D[k-1]:=D[k-1]-A[k-1,i]*D
end;
D[k-1]:=D[k-1]/A[k-1,k-1];
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var A:TM
n:integer
D:TN;
begin
n:=2;
setlength(A,n+1,n+1);
setlength(D,n+1);
A[1,1]:=1
A[1,2]:=2
D[1]:=1;
A[2,1]:=2
A[2,2]:=1
D[2]:=2;
ACHOL(A,n,D);
showmessage(format('%f,%f',[D[1],D[2]]))
end;
end.