⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.~pas

📁 matlab source code very useful to science study
💻 ~PAS
字号:
unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComObj,Buttons;
type
  TForm1 = class(TForm)
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    Label1: TLabel;
    Edit1: TEdit;
    BitBtn3: TBitBtn;
    ComboBox1: TComboBox;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    procedure BitBtn1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
  private
    {Private declarations }
  public
    { Public declarations }
  end;
  var
    Form1: TForm1;
    matlabObject:variant;
    matrix  : OleVariant;
    matrixr : OleVariant;
    matrixi : OleVariant;
    chrisr : OleVariant;
    chrisi : OleVariant;
   i,j:Integer;

implementation

{$R *.dfm}

procedure TForm1.BitBtn1Click(Sender: TObject);
var
  row,col:integer;
  str:string;
begin
If i > 4 Then
begin
 i := 1;
 j := 1;
 self.Edit1.Text :='0';
 showmessage('输入已经结束');
 Exit;
end;

 self.Label1.Caption := '当前行,列为: '+ inttostr(i)+','+inttostr(j);
 matrix[i, j] := strtofloat(self.Edit1.Text);
 str:=self.Label2.Caption+floattostr(matrix[i,j])+'      ';
 self.Label2.Caption:=str;

 If (j Mod 4) = 0 Then
 begin
 label2.Caption:=self.Label2.Caption+#13;
 i := i + 1;
 j := 1;
 end
 Else
 j := j + 1;
self.Edit1.Text :='0';

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
//matlabObject:=CreateActiveOleObject('Matlab.Application');
    // matlabObject:=GetActiveOleObject('Matlab.Application');
     matlabObject:= createOleObject('Matlab.Application');
     matrix := VarArrayCreate([1, 4, 1, 4], varDouble);
     matrixr := VarArrayCreate([1, 4, 1, 4], varDouble);
     matrixi := VarArrayCreate([1,4,1,4], varDouble);
     chrisr := VarArrayCreate([1, 4], varDouble);
     chrisi:= VarArrayCreate([1,4], varDouble);
     self.Label2.Caption:='';

self.ComboBox1.Items.Add('转置');
self.ComboBox1.Items.Add('逆矩阵');
self.ComboBox1.Items.Add('特征值');
i := 1;
j := 1;

end;

procedure TForm1.BitBtn3Click(Sender: TObject);
begin
  close;
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
var


    str:string;
    row,col:integer; //行,列

begin
       self.label4.caption:='';
     matlabObject.PutFullMatrix('T', 'base', VarArrayRef(matrix), VarArrayRef(matrixi));
    If ComboBox1.Text = '转置' Then
    begin

      matlabObject.Execute ('a=T''');
      matlabObject.GetFullMatrix('a', 'base', VarArrayRef(matrixr), VarArrayRef(matrixi));
      self.label3.caption:='转置';
      For row:= 1 To 4   do
       begin

       For col:= 1 To 4  do
        begin
        str:=self.Label4.Caption+floattostr(matrixr[row,col])+'      ';
        self.Label4.Caption:=str;
         //Print matrixr(row, col);
        end;
       label4.Caption:=self.Label4.Caption+#13;// Print
       end;
    end
    Else If ComboBox1.Text = '逆矩阵' Then
    begin
      matlabObject.Execute ('a=inv(T)');
      matlabObject.GetFullMatrix('a', 'base',VarArrayRef(matrixr),VarArrayRef(matrixi));
      self.label3.caption:='逆矩阵';

      For row:= 1 To 4   do
       begin
       For col:= 1 To 4  do
        begin
        str:=self.Label4.Caption+floattostr(matrixr[row,col])+'  ';
        self.Label4.Caption:=str;
        end;
       label4.Caption:=self.Label4.Caption+#13;// Print
       end;

    end
    Else If ComboBox1.Text = '特征值' Then
    begin
      matlabObject.Execute ('a=eig(T)');
      matlabObject.GetFullMatrix('a', 'base', VarArrayRef(chrisr), VarArrayRef(chrisi));
      self.label3.caption:='特征值';
      For row:= 1 To 4  do
      begin
         str:=self.Label4.Caption+floattostr(chrisr[row])+'  '+#13;
        self.Label4.Caption:=str;
       end;
    end
    Else
      Exit;


end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -