unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
doublearray=array of double;
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
function tras(A: array of double;B: array of double):boolean;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function tform1.tras(A: array of double;B: array of double):boolean;
var
i,j: integer;
num,root1,root2: double
//root1,root2存放相临2次计算的特征根
arr: doublearray;
tag: boolean;
cr,ci:double;
RI: array[3..13] of double;
begin
root1:=1;root2:=0
ci:=0;
RI[3]:=0.58;RI[4]:=0.90;RI[5]:=1.12;RI[6]:=1.24;RI[7]:=1.32;
RI[8]:=1.41;RI[9]:=1.45;RI[10]:=1.48;RI[11]:=1.49;RI[12]:=1.51;RI[13]:=1.56;
setlength(arr,length(B));
while root1-root2>0.00001 do //此循环的作用是用“幂法”来求最大特征值
begin
root2:=root1
for i:=0 to length(B)-1 do
begin
num:=0;
for j:=0 to length(B)-1 do
begin
num:=num+A[i*length(B)+j]*B[j];
end;
arr:=num;
end;
root1:=arr[0]/B[0]
for i:=0 to length(B) do
B:=arr;
end;
ci:=(root1-length(B))/(length(B)-1);
cr:=ci/ri[length(B)];
edit1.Text:=floattostr(ci);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
arr1: array[0..8] of double;
arr2: array[0..2] of double;
begin
arr1[0]:=1;arr1[1]:=1/5;arr1[2]:=1/5;arr1[3]:=5;
arr1[4]:=1;arr1[5]:=1;arr1[6]:=5;arr1[7]:=1;
arr1[8]:=1;
arr2[0]:=1/3;arr2[1]:=1/3;arr2[2]:=1/3;
form1.tras(arr1,arr2);
end;
end.
所有程序都在这了。还没编完呢?