Моделирование типовой динамической системы в среде “ MATLAB”

Автор работы: Пользователь скрыл имя, 14 Января 2014 в 16:18, курсовая работа

Описание работы

Цель работы: освоение приемов моделирование динамических систем с помощью ‘’MATLAB’’
Определение показателей качества динамических систем.

Содержание работы

Введение……………………………………………………………………………...3
1. Задание……………………………………………..……..…………….………..4
2. Цель……………………………………………………….………………………5
3. Основная часть…………………………………………….……………………..6
4. Эксплуатация программного продукта……………………………………….16
Заключение………………………………………………………………………….17
Список использованных источников……………………………...………………18
Приложение А Листинг программы………………………………………………19

Файлы: 1 файл

Экспертные системы отчет.doc

— 307.50 Кб (Скачать файл)

    Panel3: TPanel;

    Label28: TLabel;

    Label29: TLabel;

    Label32: TLabel;

    StringGrid11: TStringGrid;

    Panel4: TPanel;

    Label7: TLabel;

    Label14: TLabel;

    Label15: TLabel;

    StringGrid7: TStringGrid;

    procedure Button1Click(Sender: TObject);

    procedure Button2Click(Sender: TObject);

    procedure Button3Click(Sender: TObject);

    procedure Button5Click(Sender: TObject);

    procedure Button4Click(Sender: TObject);

    procedure Edit1Change(Sender: TObject);

    procedure Edit2Change(Sender: TObject);

    procedure Button6Click(Sender: TObject);

    procedure Edit1KeyPress(Sender: TObject; var Key: Char);

    procedure StringGrid1KeyPress(Sender: TObject; var Key: Char);

 

 

  private

    { Private declarations }

  public

    { Public declarations }

  end;

 

var

  Form1: TForm1;

k,i,j:integer;

sum,n,c,t:integer;

S,OC,cor,Am,IC:real;

implementation

 

{$R *.dfm}

 

function koren(step,chislo:real):real;

begin

koren:=exp((1/step)*ln(chislo));

end;

 

procedure max(StringGrid: TStringGrid;Edit: TEdit);

begin

  s:=0;

  with StringGrid do

  for i:=1 to n do

  begin

   s:=s+(strtofloat(Cells[n+2,i])*strtofloat(Cells[i,n+1]));

  end;

with edit do Text:=floattostr(roundto(s,-3));

end;

 

procedure uc(Edit:TEdit);

begin

with edit do Text:=floattostr((Am-n)/(n-1));

end;

 

 

procedure OtCo(Edit:TEdit);

begin

 

case n of

3: OC:=0.58;

4: OC:=0.9;

5: OC:=1.12;

6: OC:=1.24;

7: OC:=1.32;

8: OC:=1.41;

9: OC:=1.45;

10: OC:=1.49;

end;

with edit do Text:=floattostr(roundto(IC/OC,-3));

end;

 

procedure Schet(StringGrid: TStringGrid);

begin

with StringGrid do

begin

for j:=1 to n do

  begin

  s:=1;

  t:=0;

  for i:=1 to n do

    begin

      t:=t+1;

      s:=s*strtofloat(Cells[i,j]);

    end;

  Cells[t+1,j]:=floattostr(roundto((koren(t,s)),-3));

  end;

for i:=1 to n+1 do

  begin

  t:=0;

  s:=0;

  for j:=1 to n do

    begin

    t:=t+1;

    s:=s+strtofloat(Cells[i,j]);

    end;

  Cells[i,t+1]:=floattostr(roundto(s,-3));

  end;

    s:=0;

  with StringGrid do

  for i:=1 to n do

  begin

   Cells[n+2,i]:=floattostr(roundto((strtofloat(Cells[n+1,i])/strtofloat(Cells[n+1,n+1])),-3));

   end; end; end;

 

procedure SaveStringGrid(StringGrid: TStringGrid; const FileName: TFileName);

var

   f:    TextFile;

begin

   AssignFile(f, FileName);

   Rewrite(f);

   with StringGrid do

   begin

     // Write number of Columns/Rows

    Writeln(f, ColCount);

     Writeln(f, RowCount);

     // loop through cells

    for i := 0 to ColCount - 1 do

       for j := 0 to RowCount - 1 do

         Writeln(F, Cells[i, j]);

  end;

   CloseFile(F);  end;

 

procedure LoadStringGrid(StringGrid: TStringGrid; const FileName: TFileName);

var

   f:          TextFile;

   iTmp: Integer;

   strTemp:    String;

begin

   AssignFile(f, FileName);

   Reset(f);

   with StringGrid do

   begin

     // Get number of columns

    Readln(f, iTmp);

     ColCount := iTmp;

     // Get number of rows

    Readln(f, iTmp);

     RowCount := iTmp;

     // loop through cells & fill in values

    for i := 0 to ColCount - 1 do

       for j := 0 to RowCount - 1 do

       begin

         Readln(f, strTemp);

         Cells[i, j] := strTemp;

       end;

   end;

   CloseFile(f);  end;

 

procedure Sbor;

var

a,b:integer;

z,s:real;

begin

a:=5;

b:=3;

Form1.Panel3.Visible:=true;

LoadStringGrid(form1.StringGrid11, '11.txt');

For i:=1 to a do

begin

  for j:=0 to b+2 do

  begin

    if j=0 then form1.StringGrid11.Cells[i,j]:=inttostr(i);

 

  form1.StringGrid11.Cells[i,1]:=floattostr(roundto(strtofloat(Form1.StringGrid1.Cells[a+2,i]),-3));

  end;      end;

for i:=2 to b+1 do

begin

  form1.StringGrid11.Cells[1,i]:=floattostr(roundto(strtofloat(form1.StringGrid2.Cells[5,i-1]),-3));

  form1.StringGrid11.Cells[2,i]:=floattostr(roundto(strtofloat(form1.StringGrid3.Cells[5,i-1]),-3));

  form1.StringGrid11.Cells[3,i]:=floattostr(roundto(strtofloat(form1.StringGrid4.Cells[5,i-1]),-3));

  form1.StringGrid11.Cells[4,i]:=floattostr(roundto(strtofloat(form1.StringGrid5.Cells[5,i-1]),-3));

  form1.StringGrid11.Cells[5,i]:=floattostr(roundto(strtofloat(form1.StringGrid6.Cells[5,i-1]),-3));

  //form1.StringGrid11.Cells[6,i]:=floattostr(roundto(strtofloat(form1.StringGrid7.Cells[5,i-1]),-3));

  end;

 

for j:=2 to b+1 do

begin

  z:=0;

  for i:=1 to a do

  begin

    z:=z+(strtofloat(form1.StringGrid11.Cells[i,1])*strtofloat(form1.StringGrid11.Cells[i,j]));

    form1.StringGrid11.Cells[a+1,j]:= floattostr(roundto(z,-4));

     if z>s then

    begin

      s:=z;

      form1.Label28.Caption:='Автомобиль '+form1.StringGrid11.Cells[0,j];

    end;   end; end; end;

 

procedure TForm1.Button1Click(Sender: TObject);

 begin

If messageBox(Handle,'Сохранить  изменения ?','Выход',

mb_YesNoCancel or mb_iconquestion)=mrYes then

SaveStringGrid(StringGrid1, 'temp.txt');

end;

 

procedure TForm1.Button2Click(Sender: TObject);

begin

form1.Edit1.Text:='';

If messageBox(Handle,'Загрузить из файла ?','Выход',

mb_YesNoCancel or mb_iconquestion)=mrYes then

  begin

   form1.Button2.Enabled:=false;

   form1.Button1.Enabled:=false;

   LoadStringGrid(StringGrid1, 'temp.txt');

   form1.Edit1.Text:=inttostr(form1.StringGrid1.ColCount-1);

  end;

  form1.StringGrid1.Options:=[goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goAlwaysShowEditor];

 end;

 

procedure preob(StringGrid: TStringGrid);

var

  s:string;

  A:integer;

begin

with StringGrid do

begin

for i:=1 to n do

begin

  for j:=1 to n do

  begin

      s:=Cells[i,j];

      if length(s)>2 then

      begin

        for a:=1 to length(s) do

        begin

          if s[a]='/' then

          begin

            Cells[i,j]:=floattostr(roundto(strtofloat(s[a-1])/strtofloat(s[a+1]),-3));;

          end; 

        end;

      end;

  end;

  end;

  end;

end;

 

 

procedure TForm1.Button3Click(Sender: TObject);

begin

preob(StringGrid1);

Schet(StringGrid1);

Amax (StringGrid1,edit3);

Am:=strtofloat(form1.Edit3.Text);

uc(edit4);

Ic:=strtofloat(form1.Edit4.Text);

OtCo(edit5);

LoadStringGrid(StringGrid2, '10.txt');

LoadStringGrid(StringGrid3, '10.txt');

LoadStringGrid(StringGrid4, '10.txt');

LoadStringGrid(StringGrid5, '10.txt');

LoadStringGrid(StringGrid6, '10.txt');

//form1.Panel1.Visible:=false;

Form1.Panel2.Visible:=true;

form1.StringGrid2.Cells[0,0]:=form1.StringGrid1.Cells[0,1];

form1.StringGrid3.Cells[0,0]:=form1.StringGrid1.Cells[0,2];

form1.StringGrid4.Cells[0,0]:=form1.StringGrid1.Cells[0,3];

form1.StringGrid5.Cells[0,0]:=form1.StringGrid1.Cells[0,4];

form1.StringGrid6.Cells[0,0]:=form1.StringGrid1.Cells[0,5];

end;

 

procedure TForm1.Button5Click(Sender: TObject);

begin

form1.Edit2.Text:='';

form1.StringGrid2.Options:=[goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goAlwaysShowEditor];

form1.StringGrid3.Options:=[goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goAlwaysShowEditor];

form1.StringGrid4.Options:=[goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goAlwaysShowEditor];

form1.StringGrid5.Options:=[goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goAlwaysShowEditor];

form1.StringGrid6.Options:=[goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goAlwaysShowEditor];

form1.StringGrid11.Options:=[goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goAlwaysShowEditor];

 

If messageBox(Handle,'Загрузить из файла ?','Выход',

mb_YesNoCancel or mb_iconquestion)=mrYes then

begin

   form1.Button5.Enabled:=false;

   form1.Button4.Enabled:=false;

LoadStringGrid(StringGrid2, '2.txt');

LoadStringGrid(StringGrid3, '3.txt');

LoadStringGrid(StringGrid4, '4.txt');

LoadStringGrid(StringGrid5, '5.txt');

LoadStringGrid(StringGrid6, '6.txt');

form1.Edit2.Text:=inttostr(form1.StringGrid2.RowCount-1);

end;

end;

 

procedure TForm1.Button4Click(Sender: TObject);

begin

If messageBox(Handle,'Сохранить  изменения ?','Выход',

mb_YesNoCancel or mb_iconquestion)=mrYes then

Begin

SaveStringGrid(StringGrid2, '2.txt');

SaveStringGrid(StringGrid3, '3.txt');

SaveStringGrid(StringGrid4, '4.txt');

SaveStringGrid(StringGrid5, '5.txt');

SaveStringGrid(StringGrid6, '6.txt');

end; end;

 

procedure TForm1.Edit1Change(Sender: TObject);

begin

 

if edit1.Text<>'' then

begin

  if (strtoint(form1.Edit1.Text)<11) and (strtoint(form1.Edit1.Text)>2) then

  begin

    n:=strtoint(form1.Edit1.text);

    form1.StringGrid1.ColCount:=n+3;

    form1.StringGrid1.RowCount:=n+2;

  end; end; end;

 

procedure Izmeneniematric(StringGrid: TStringGrid);

begin

with StringGrid do

begin

n:=strtoint(form1.Edit2.text);

ColCount:=n+3;

RowCount:=n+2;

end; end;

 

procedure TForm1.Edit2Change(Sender: TObject);

begin

if edit2.Text<>'' then

begin

  if (strtoint(form1.Edit1.Text)<11) and (strtoint(form1.Edit1.Text)>2) then

  begin

    izmeneniematric(stringgrid2);

    izmeneniematric(stringgrid3);

    izmeneniematric(stringgrid4);

    izmeneniematric(stringgrid5);

    izmeneniematric(stringgrid6);

  end; end; end;

 

procedure TForm1.Button6Click(Sender: TObject);

begin

 

preob(StringGrid2);

preob(StringGrid3);

preob(StringGrid4);

preob(StringGrid5);

preob(StringGrid6);

Schet(StringGrid2);

Schet(StringGrid3);

Schet(StringGrid4);

Schet(StringGrid5);

Schet(StringGrid6);

max (StringGrid2,edit6);

max (StringGrid3,edit10);

max (StringGrid4,edit7);

max (StringGrid5,edit11);

max (StringGrid6,edit8);

n:=form1.StringGrid2.RowCount-2;

Am:=strtofloat(form1.Edit6.Text);

uc(edit14);

Am:=strtofloat(form1.Edit10.Text);

uc(edit23);

Am:=strtofloat(form1.Edit7.Text);

uc(edit17);

Am:=strtofloat(form1.Edit11.Text);

uc(edit25);

Am:=strtofloat(form1.Edit8.Text);

uc(edit19);

IC:=strtofloat(form1.Edit14.Text);

OtCo(edit15);

IC:=strtofloat(form1.Edit23.Text);

OtCo(edit22);

IC:=strtofloat(form1.Edit17.Text);

OtCo(edit16);

IC:=strtofloat(form1.Edit25.Text);

OtCo(edit24);

IC:=strtofloat(form1.Edit19.Text);

OtCo(edit18);

Sbor;

end;

 

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);

begin

if Not (Key in ['0'..'9', #8])then Key:=#0;

end;

 

procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);

begin

for i:=1 to form1.StringGrid1.ColCount do

  for j:=1 to form1.StringGrid1.RowCount do

    if Not (Key in ['0'..'9','/', #8])then Key:=#0;

end;

end.




Информация о работе Моделирование типовой динамической системы в среде “ MATLAB”