我自己在检索里查了一个,但是换了一组数据,在运行期里出错,不知道为什么。说是
数据类型不匹配,能帮我看看吗?
type
TMatrix = array of array of Extended;
const
PSUMInfinity: Extended = 1E30;
PSUMChangeBaseZero: Extended = 1E-15;
PSUMAccumulateZero: Extended = 1E-15;
PSUMZero: Extended = 1E-15;
procedure PSUM(d: Integer
m, n: Integer
var id: array of Integer;
a: TMatrix
var k: Integer);
implementation
{$R *.DFM}
procedure PSUM(d: Integer
m, n: Integer
var id: array of Integer;
a: TMatrix
var k: Integer);
var
i, j, L: Integer;
f, exm: Extended;
function SI(c, cr: Extended): Extended;
begin
if Abs(c) > cr then Result := c else Result := 0;
end;
begin
repeat
exm := PSUMInfinity * d;
k := -1;
for j := 1 to n do
if (d * a[0, j] > PSUMAccumulateZero) //就是这一句运行期有错!
and (-d * (a[0, j] - exm) > 0) then begin
exm := a[0, j];
k := j;
end;
if k = -1 then begin
k := 0;
Break;
end;
if k > n - m then Break;
exm := PSUMInfinity;
L := -1;
for i := 1 to m do begin
f := a[i, 0] / a[i, k];
if (a[i, k] > PSUMChangeBaseZero)
and (exm > f) then begin
exm := f;
L := i;
end;
end;
if L = -1 then Break
id[L] := k;
for j := 0 to n do
if j <> k then a[L, j] := a[L, j] / a[L, k];
a[L, k] := 1;
for i := 0 to m do
if i <> L then begin
for j := 0 to n do
if j <> k then
a[i, j] := SI(a[i, j] - a[L, j] * a[i, k], PSUMChangeBaseZero);
a[i, k] := SI(a[i, k] * (1 - a[L, k]), PSUMChangeBaseZero);
end;
until False;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
a: TMatrix;
id: array [0..3] of Integer;
k: Integer;
begin
SetLength(a, 4, 6);
a[0, 0] := 0
a[0, 1] := -4
a[0, 2] := -1
a[0, 3] := 0
a[0, 4] := 0
a[0, 5] := 0
a[0, 6] := 0
a[0,7]:=0;
a[1, 0] := 6
a[1, 1] := 4
a[1, 2] := 3
a[1, 3] := -1
a[1, 4] := 0
a[1, 5] := 1
a[1, 6] := 0
a[1,7]:=0;
a[2, 0] := 3
a[2, 1] := 1
a[2, 2] := 2
a[2, 3] := 0
a[2, 4] := 1
a[2, 5] := 0
a[2, 6] := 1
a[2,7]:=0;
a[3, 0] := 3
a[3, 1] := 3
a[3, 2] := 1
a[3, 3] := 0
a[3, 4] := 0
a[3, 5] := 0
a[3, 6] := 0
a[3,7]:=1;
id[0] := 0
id[1] := 6
id[2] := 3
id[3]:=3;
PSUM(1, 3, 7, id, a, k);
if k = 0 then
ShowMessage('failed')
else
showmessage(format('y=%f, x1=%f, x2=%f',[a[0,0],a[1,0],a[2,0]]));
end;
end.