L
lmk
Unregistered / Unconfirmed
GUEST, unregistred user!
看看程序错在哪了?中间的2个做标记的地方。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TDoubleArray = array[0..2] of Double;
TDoubleArray2 = array[0..2] of array[0..2] of Double;
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Edit7: TEdit;
Edit8: TEdit;
Edit9: TEdit;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
function Trans(A: TDoubleArray
B: TDoubleArray2): TDoubleArray;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
arr1: TDoubleArray;
arr2: TDoubleArray2;
arr3: TDoubleArray;
num: double;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
arr1[0]:=1/3;arr1[1]:=1/3;arr1[2]:=1/3;
arr2[0][0]:=strtofloat(edit1.Text);arr2[0][1]:=strtofloat(edit2.Text);arr2[0][2]:=strtofloat(edit3.Text);
arr2[1][0]:=strtofloat(edit4.Text);arr2[1][1]:=strtofloat(edit5.Text);arr2[1][2]:=strtofloat(edit6.Text);
arr2[2][0]:=strtofloat(edit7.Text);arr2[2][1]:=strtofloat(edit8.Text);arr2[2][2]:=strtofloat(edit9.Text);
end;
{如过把上面数组直接付值就可以运行
arr2[0][0]:=1;arr2[0][1]:=1;arr2[0][2]:=1/5;
arr2[1][0]:=1;arr2[1][1]:=1;arr2[1][2]:=1/3;
arr2[2][0]:=5;arr2[2][1]:=3;arr2[2][2]:=1;
}
procedure TForm1.Button1Click(Sender: TObject);
begin
arr3:=Trans(arr1,arr2);
edit1.Text:=floattostr(arr3[0]);
edit2.Text:=floattostr(arr3[1]);
edit3.Text:=floattostr(arr3[2]);
edit4.Text:=floattostr(num);
end;
function tform1.Trans(A: TDoubleArray
B: TDoubleArray2): TDoubleArray
var
arr: TDoubleArray;
tB: TDoubleArray2;
i,j: integer;
begin
for i:=0 to length(A)-1 do
for j:=0 to length(A)-1 do
tB[j]:=B[j];
edit1.Text:=floattostr(tB[0][0]);
edit2.Text:=floattostr(tB[0][1]);
edit3.Text:=floattostr(tB[0][2]);
edit4.Text:=floattostr(num);
num:=0;
for i:=0 to length(A)-1 do
begin
arr:=0;
for j:=0 to length(A)-1 do
begin
arr:=arr+A[j]*tB[j];
end;
num:=num+arr;
end;
for i:=0 to length(arr) do
begin
arr:=arr/num;
end;
for i:=0 to length(A)-1 do
if abs(A-arr)>0.01 then
arr:=Trans(arr,tB);
result:=arr
//这样返回安全吗?
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TDoubleArray = array[0..2] of Double;
TDoubleArray2 = array[0..2] of array[0..2] of Double;
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Edit7: TEdit;
Edit8: TEdit;
Edit9: TEdit;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
function Trans(A: TDoubleArray
B: TDoubleArray2): TDoubleArray;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
arr1: TDoubleArray;
arr2: TDoubleArray2;
arr3: TDoubleArray;
num: double;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
arr1[0]:=1/3;arr1[1]:=1/3;arr1[2]:=1/3;
arr2[0][0]:=strtofloat(edit1.Text);arr2[0][1]:=strtofloat(edit2.Text);arr2[0][2]:=strtofloat(edit3.Text);
arr2[1][0]:=strtofloat(edit4.Text);arr2[1][1]:=strtofloat(edit5.Text);arr2[1][2]:=strtofloat(edit6.Text);
arr2[2][0]:=strtofloat(edit7.Text);arr2[2][1]:=strtofloat(edit8.Text);arr2[2][2]:=strtofloat(edit9.Text);
end;
{如过把上面数组直接付值就可以运行
arr2[0][0]:=1;arr2[0][1]:=1;arr2[0][2]:=1/5;
arr2[1][0]:=1;arr2[1][1]:=1;arr2[1][2]:=1/3;
arr2[2][0]:=5;arr2[2][1]:=3;arr2[2][2]:=1;
}
procedure TForm1.Button1Click(Sender: TObject);
begin
arr3:=Trans(arr1,arr2);
edit1.Text:=floattostr(arr3[0]);
edit2.Text:=floattostr(arr3[1]);
edit3.Text:=floattostr(arr3[2]);
edit4.Text:=floattostr(num);
end;
function tform1.Trans(A: TDoubleArray
B: TDoubleArray2): TDoubleArray
var
arr: TDoubleArray;
tB: TDoubleArray2;
i,j: integer;
begin
for i:=0 to length(A)-1 do
for j:=0 to length(A)-1 do
tB[j]:=B[j];
edit1.Text:=floattostr(tB[0][0]);
edit2.Text:=floattostr(tB[0][1]);
edit3.Text:=floattostr(tB[0][2]);
edit4.Text:=floattostr(num);
num:=0;
for i:=0 to length(A)-1 do
begin
arr:=0;
for j:=0 to length(A)-1 do
begin
arr:=arr+A[j]*tB[j];
end;
num:=num+arr;
end;
for i:=0 to length(arr) do
begin
arr:=arr/num;
end;
for i:=0 to length(A)-1 do
if abs(A-arr)>0.01 then
arr:=Trans(arr,tB);
result:=arr
//这样返回安全吗?
end;
end.