计算行列式值:
type
TArray=array[0..10,0..10] of double;
function Matrix(n:integer;a:TArray):double;
const e=0.0000001;
var
i,j,k:integer;
d2,d3:double;
exch:boolean;
begin
result:=0;
for i:=0 to n-1 do
begin
exch:=true;
if abs(a[i,i])<e then
begin
exch:=false;
for j:=i+1 to n-1 do
if abs(a[j,i])>e then
begin
exch:=true;
for k:=i to n-1 do
begin
d2:=a[i,k];
a[i,k]:=a[j,k];
a[j,k]:=d2;
end;
break;
end;
if exch then break;
end;
if not(exch) then exit;
d2:=a[i,i];
for j:=i+1 to n-1 do
begin
d3:=a[j,i];
for k:=i to n-1 do
begin
a[j,k]:=a[j,k]-a[i,k]/d2*d3;
end;
end;
end;
result:=1;
for i:=0 to n-1 do Result:=Result*a[i,i];
end;
procedure TForm1.Button2Click(Sender: TObject);
var
a:Tarray ;
d:double;
begin
a[0,0]:=0;
a[0,1]:=0;
a[1,0]:=0;
a[1,1]:=0;
showmessage(floattostr(Matrix(2,a)));
a[0,0]:=2;
a[0,1]:=3;
a[1,0]:=4;
a[1,1]:=5
// -2
showmessage(floattostr(Matrix(2,a)));
end;