10.1. .
. 13.
10.2. .
. 14.
Simulink.
, , Simulink, .
10.3. .
. 15.
Simulink.
, , Simulink, .
, .
- MatLab Simulink.
. 14. Simulink.
.
- .
- .
. .
- :
1) ;
2) , ;
3) ;
4) ;
5) .
- :
1) ;
2) ;
3) .
, , , .
, . - II . MatLab Simulink, , .
|
|
, - ; , ; .
1. .. . : - , 1992.
2. .. . : - , 2004.
3. . .. MatLAB . : - , 2002.
4. . MatLAB: . : -
"", 2003.
5. .. Delphi. : - , 1997.
6. .. MathCad 14. .: - , 2008.
. .
Unit Unit1;
Interface
Uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, Buttons, ExtCtrls, jpeg, pngimage, Grids,CategoryButtons;
Type
TMass= array of array of Real;
TVector= array of Real;
TVec= array of array of Integer;
Type
TForm1 = class(TForm)
procedure BitBtn4Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure RadioGroup1Click(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean);
procedure Edit12Change(Sender: TObject);
Private
procedure RK22 (A:TMass; n: integer; var t,U1: Extended; h: real; var X: TVector);
function RP(n: integer; A: TMass; X: TVector; t: real; U1:Extended): Real;
function Read(Str: string; i,j: integer): Real;
function ReadPS(Str: string; j,n: integer): Integer;
function Signal(i: byte;t: Extended): Real;
function Trapzion(t: Extended): Real;
function Harmonic(t: Extended): Real;
function Impulse(t: Extended): Real;
function ReadSignal(t: Extended): Extended;
End;
Var
Form1: TForm1;
C,A: TMass;
F,Z: TVector;
P: TVec;
t: Extended;
i,j,k: integer;
implementation
uses Unit2, Unit3;
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
Var
tk: real;
n: integer;
X: TVector;
U: Extended;
U1: Extended;
Const
h = 0.001;
Begin
Form2.Series1.Clear;
Form2.Series2.Clear;
Form1.Left:= (Screen.Width - Form1.Width) div 2;
Form1.Top:= Screen.Height - Form1.Height - 50;
Form2.Left:= (Screen.Width - Form2.Width) div 2;
Form2.Top:= Form1.Top - 250;
Form2.Show;
t:= 0; //
tk:= StrToFloat(Edit13.Text); //
n:= StrToInt(Edit12.Text); // -
SetLength(X,n);
|
|
for i:= 0 to (n-1) do
begin
X[i]:=0;
end;
i:=0;
for j:= 0 to n do
begin
SetLength(P,i+1,j+1);
SetLength(C,i+1,j+1);
P[i,j]:= ReadPS(Edit6.Text,j,n);
C[i,j]:= Read(Edit6.Text,i,j);
end;
P:= nil;
SetLength(P,n,(n+1));
SetLength(A,n,(n+1));
for i:= 0 to (n-1) do
for j:= 0 to n do
begin
P[i,j]:= ReadPS(StringGrid2.Rows[i].Text,j,n);
A[i,j]:= Read(StringGrid2.Rows[i].Text,i,j);
end;
while (t<tk) do
begin
U1:= ReadSignal(t);
RK22(A,n,t,U1,h,X);
U:=0;
for j:= 0 to n do
begin
if (j<n) then
U:= U + C[0,j]*X[j]
else
U:= U + C[0,j]*U1;
end;
Form2.Series1.AddXY(t,U);
t:=t+h;
end;
Form2.Chart1.Title.Caption:= ' ';
case RadioGroup1.ItemIndex of
0:Form2.Chart1.Title.Caption:= Form2.Chart1.Title.Caption + ' ';
1:Form2.Chart1.Title.Caption:= Form2.Chart1.Title.Caption + ' ';
2:Form2.Chart1.Title.Caption:= Form2.Chart1.Title.Caption + ' ';
3:Form2.Chart1.Title.Caption:= Form2.Chart1.Title.Caption + ' ';
end;
end;
procedure TForm1.BitBtn3Click(Sender: TObject);
begin
Form3:= TForm3.Create(Self);
try
begin
Form3.Image1.Picture.LoadFromFile('info.png');
Form3.ShowModal;
end;
finally
Form3.Free;
end;
end;
procedure TForm1.RadioGroup1Click(Sender: TObject);
Begin
Form2.Close;
case RadioGroup1.ItemIndex of
0: i:=0;
1: i:=1;
2: i:=2;
3: i:=3;
end;
TRadioButton(RadioGroup1.Controls[i]).Font.Size:= 9;
Timer2.Enabled:= True;
Image2.Picture.LoadFromFile('iChat.png');
Edit7.Text:='';
Edit8.Text:='';
Edit9.Text:='';
Edit10.Text:='';
Edit11.Text:='';
End;
function TForm1.Read(Str: string; i,j: integer): Real;
Var
k1,k2: integer;
Begin
if P[i,j]=0 then
begin
Result:=0;
end
else
begin
if (j=0) then
k1:= 1
else
k1:= P[i,j-1] + 5;
k2:= P[i,j] - k1;
Result:= StrToFloat(copy(Str,k1,k2));
end;
End;
function TForm1.ReadPS(Str: string; j, n: integer): integer;
Var
S, Z: string;
Begin
Z:= '*X[';
Inc(j);
if (j<=n) then
begin
S:= Z + IntToStr(j) + ']';
result:= Pos(S,Str);
end
else
result:= Pos('*U',Str);
End;
function TForm1.ReadSignal(t: Extended): Extended;
Begin
case RadioGroup1.ItemIndex of
0: result:=Signal(0,t);
1: begin
if (Edit7.Text='') or (Edit8.Text='') or (Edit9.Text='') or(Edit10.Text='') or (Edit11.Text='') then
begin
Mes;
exit;
end;
result:=Signal(1,t);
end;
2: begin
if (Edit7.Text='') or (Edit9.Text='') or (Edit11.Text='') then
begin
Mes;
exit;
end;
result:=Signal(2,t);
end;
3: begin
if (Edit7.Text='') or (Edit9.Text='') or(Edit10.Text='') or (Edit11.Text='') then
begin
Mes;
exit;
end;
result:=Signal(3,t);
end;
end;
End;
procedure TForm1.RK22(A: TMass; n: integer; var t,U1: Extended; h: real; var X: TVector);
Var
h2: real;
X1: TVector;
begin
h2:=h/2;
SetLength(X1,n);
SetLength(F,n);
for i:= 0 to (n-1) do
begin
F[i]:= RP(n,A,X,t,U1);
X1[i]:= X[i]+h2*F[i];
end;
for i:= 0 to (n-1) do
begin
F[i]:= RP(n,A,X1,t,U1);
X[i]:=X[i]+h*F[i];
end;
End;
function TForm1.RP(n: integer; A: TMass; X: TVector; t: real;U1: Extended): Real;
Begin
result:= 0;
for j:= 0 to n do
begin
if j=0 then
result:= A[i,j]*X[j]
else
if (j<n) then
result:= result + A[i,j]*X[j]
else
result:= result + A[i,j]*U1;
end;
End;
function TForm1.Signal(i: byte; t: Extended): Real;
Begin
case i of
0: begin
result:=1;
Form2.Series2.AddXY(t,result);
end;
1: result:= Trapzion(t);
2: result:= Harmonic(t);
3: result:= Impulse(t);
End;
End;
procedure TForm1.Timer2Timer(Sender: TObject);
Const
L = 474;
Begin
if RadioGroup1.ItemIndex=0 then
|
|
begin
Form1.Width:= L;
Form1.Left:= (Screen.Width - Form1.Width) div 2;
Timer2.Enabled:= False;
exit;
end;
FormPlus;
while (Form1.ClientWidth < 859) do
begin
Form1.ClientWidth:= Form1.ClientWidth + 1;
Form1.Left:= (Screen.Width - Form1.Width) div 2;
end;
GroupBox8.Caption:= '';
GroupBox8.Visible:= True;
GroupBox9.Visible:= True;
SpeedButton1.Caption:= 'A';
if RadioGroup1.ItemIndex=1 then
begin
GroupBox8.Caption:= ' ';
GroupBox10.Visible:= True;
GroupBox11.Visible:= True;
GroupBox12.Visible:= True;
GroupBox13.Visible:= True;
GroupBox14.Visible:= True;
Edit7.Visible:= True;
Edit8.Visible:= True;
Edit9.Visible:= True;
Edit10.Visible:= True;
Edit11.Visible:= True;
SpeedButton2.Caption:= 't0';
SpeedButton3.Caption:= 't1';
SpeedButton4.Caption:= 't2';
SpeedButton5.Caption:= 't3';
Image1.Picture.LoadFromFile('Trapzion.png');
End;
if RadioGroup1.ItemIndex=2 then
Begin
GroupBox8.Caption:= ' ';
GroupBox10.Visible:= True;
GroupBox12.Visible:= True;
GroupBox14.Visible:= True;
Edit7.Visible:= True;
Edit9.Visible:= True;
Edit11.Visible:= True;
SpeedButton3.Caption:= 'w';
SpeedButton5.Caption:= 'f0';
Image1.Picture.LoadFromFile('Harmonic.png');
End;
if RadioGroup1.ItemIndex=3 then
begin
GroupBox8.Caption:= ' ';
GroupBox10.Visible:= True;
GroupBox12.Visible:= True;
GroupBox13.Visible:= True;
GroupBox14.Visible:= True;
Edit7.Visible:= True;
Edit9.Visible:= True;
Edit10.Visible:= True;
Edit11.Visible:= True;
SpeedButton3.Caption:= 't1';
SpeedButton4.Caption:= 't2';
SpeedButton5.Caption:= 't3';
Image1.Picture.LoadFromFile('Impulse.png');
end;
if (Form1.ClientWidth = 859) then
StatusBar1.Panels[4].Text:=' ';
Timer2.Enabled:= False;
End;
function TForm1.Trapzion(t: Extended): Real;
Var
x0,x1,x2,x3,x4, l, a: Real;
Begin
SetLength(Z,5);
Z[0]:= StrToFloat(Edit7.Text); // A
Z[1]:= StrToFloat(Edit9.Text); // t1
Z[2]:= StrToFloat(Edit10.Text); // t2
Z[3]:= StrToFloat(Edit11.Text); // t3
Z[4]:= StrToFloat(Edit8.Text); // t0
l:= Z[2]+Z[3];
if t<Z[4] then
begin
result:=0;
Form2.Series2.AddXY(t,result);
exit;
end
else
begin
t:= t - Z[4];
if t>l then
begin
i:= Trunc(t/l);
a:= i*l;
end
else
a:=0;
end;
x0:= a;
x1:= (Z[2] - Z[1])/2 + a;
x2:= 0.5*Z[1] + 0.5*Z[2] + a;
x3:= Z[2] + a;
x4:= Z[2] + Z[3] + a;
if (t>=x0) and (t<x1) then
result:= Z[0]*((t-x0)/(x1-x0));
if (t>=x1) and (t<x2) then
result:= Z[0];
if (t>=x2) and (t<=x3) then
result:= Z[0]*(1-((t-x2)/(x3-x2)));
if (t>x3) and (t<x4) then
result:= 0;
t:= t + Z[4];
Form2.Series2.AddXY(t,result);
End;
function TForm1.Harmonic(t: Extended): Real;
var
A, w, f: Real;
begin
A:= StrToFloat(Edit7.Text);
w:= StrToFloat(Edit9.Text);
f:= StrToFloat(Edit11.Text);
result:= A*sin(w*t+f);
Form2.Series2.AddXY(t,result);
End;
function TForm1.Impulse(t: Extended): Real;
Var
x1,x2,x3, l, a: Real;
Begin
SetLength(Z,4);
Z[0]:= StrToFloat(Edit7.Text); // A
Z[1]:= StrToFloat(Edit9.Text); // t1
Z[2]:= StrToFloat(Edit10.Text); // t2
Z[3]:= StrToFloat(Edit11.Text); // t3
l:= Z[2]+Z[3];
if t<Z[1] then
begin
result:=0;
Form2.Series2.AddXY(t,result);
exit;
end;
t:=t-Z[1];
if t>l then
begin
i:= Trunc(t/l);
a:= i*l;
end
else
a:=0;
x1:= a;
x2:= Z[2] + a;
x3:= Z[2] + Z[3]+ a;
|
|
if (t>=x1) and (t<x2) then result:= Z[0];
if (t>=x2) and (t<x3) then result:= 0;
t:= t + Z[1];
Form2.Series2.AddXY(t,result);
End;
End.