Курсовая работа: Анализ методов определения минимального, максимального значения функции при наличии ограничений
z:=fz(x,y,a,b,c,d,e,f);
//------------------------------------------------------------
if ((abs(x-x0)<0.01)and (abs(y-y0)<0.01) and (abs(z-z0)<0.01)) then break;
End;
EX.Text:=floattostr(x);
EY.Text:=floattostr(y);
EZ.Text:=floattostr(z);
EK.Text:=inttostr(k+1);
except
ShowMessage('Не удалось найти экстремум, попробуйте другой метод.');
end;
end;
procedure TFMain.BSpuskClick(Sender: TObject);
var k, i:Integer;
x0, y0, z0, x, y, z, Fx, Fy, M, _bez:Double; // a, b, c, d, e, f,
H : array[1..2,1..2] of Double;
begin
if (RBMin.Checked = false) and (RBMax.Checked = false) then RBMin.Checked := true;
if Miter.Count > 0 then MIter.Clear;
EU.Enabled := true;
k:=0;
Zapoln();
//-------------------------------
_bez:=(b*d-e*a)/(a*c-b*b);
EYb.Text:=floattostr(_bez);
EXb.Text:=floattostr(-(b*_bez+d)/a);
//-------------------------------
MIter.Items.Add('---------------------');
x:=StrToFloat(EX0.Text);
y:=StrToFloat(EY0.Text);
z:=fz(x,y,a,b,c,d,e,f);
MIter.Items.Add('k='+inttostr(k)+' '+
'x'+inttostr(k)+'='+floattostr(x)+' '+
'y'+inttostr(k)+'='+floattostr(y)+' '+
'F(x,y)='+floattostr(z));
H[1,1]:=2*a;
H[1,2]:=2*b;
H[2,1]:=2*b;
H[2,2]:=2*c;
for i := 1 to 1000 do
Begin
k:=k+1;
MIter.Items.Add('---------------------');
x0:=x;
y0:=y;
z0:=fz(x0,y0,a,b,c,d,e,f);
Fx:=dx(x0, y0, b, d, a);
Fy:=dy(x0, y0, b, e, c);
M:=(Fx*Fx + Fy*Fy)/(Fx*(H[1,1]*Fx+H[1,2]*Fy) + Fy*(H[2,1]*Fx+H[2,2]*Fy));
if RBMin.Checked then
begin
x:=x0-M*Fx;
y:=y0-M*Fy;
end
else if RBMax.Checked then
Begin
x:=x0+M*Fx;
y:=y0+M*Fy;
End;
z:=fz(x,y,a,b,c,d,e,f);
MIter.Items.Add('k='+inttostr(k)+' | '+
'x'+inttostr(k)+'='+floattostr(x)+' | '+
'y'+inttostr(k)+'='+floattostr(y)+' | '+
'F(x,y)='+floattostr(z)+' | '+
'u'+inttostr(k-1)+'='+floattostr(M));
if ((abs(x-x0)<0.01)and (abs(y-y0)<0.01) and (abs(z-z0)<0.01)) then break;
End;
EX.Text:=floattostr(x);
EY.Text:=floattostr(y);
EZ.Text:=floattostr(z);
EK.Text:=inttostr(k);
EU.Text:=floattostr(M);
end;
procedure TFMain.BStopClick(Sender: TObject);
begin
_BoolStop:=true;
end;
Function Znak(chislo : Double; Stroka:String) : String;
begin
if (chislo > 0) then
if (chislo <> 1) then Result:='+'+FloatToStr(chislo)+Stroka
else Result:='+'+Stroka
else if (chislo < 0) then
if (chislo <> -1) then Result:=FloatToStr(chislo)+Stroka
else Result:='-'+Stroka
else Result:='';
end;
Function ZnakN(chislo : Double; Stroka:String) : String;
begin
if (chislo > 0) then
if chislo <> 1 then Result:=FloatToStr(chislo)+Stroka
else Result:=Stroka
else if (chislo < 0) then
if (chislo <> -1) then Result:=FloatToStr(chislo)+Stroka
else Result:='-'+Stroka
else Result:='';
end;
Function ZnakKon(chislo : Double) : String;
begin
if (chislo > 0) then Result:='+'+FloatToStr(chislo)
else if chislo = 0 then Result:=''
else Result:=FloatToStr(chislo);
end;
procedure TFMain.Zapoln();
begin
with FMain do
begin
a:=DBGMain.Fields[1].AsFloat;
b:=DBGMain.Fields[2].AsFloat;
c:=DBGMain.Fields[3].AsFloat;
d:=DBGMain.Fields[4].AsFloat;
e:=DBGMain.Fields[5].AsFloat;
f:=DBGMain.Fields[6].AsFloat;
Am[1,1]:=DBGMain.Fields[9].AsFloat;
Am[1,2]:=DBGMain.Fields[10].AsFloat;
Bm[1]:=DBGMain.Fields[11].AsFloat;
Am[2,1]:=DBGMain.Fields[12].AsFloat;
Am[2,2]:=DBGMain.Fields[13].AsFloat;
Bm[2]:=DBGMain.Fields[14].AsFloat;
Am[3,1]:=DBGMain.Fields[15].AsFloat;
Am[3,2]:=DBGMain.Fields[16].AsFloat;
Bm[3]:=DBGMain.Fields[17].AsFloat;
Am[4,1]:=DBGMain.Fields[18].AsFloat;
Am[4,2]:=DBGMain.Fields[19].AsFloat;
Bm[4]:=DBGMain.Fields[20].AsFloat;
end;
end;
procedure TFMain.ZnakConstrain();
begin
with FMain do
begin
nomer:=StrToInt(EVar.Text);
Q.Close;
Q.SQL.Text:='select znak1, znak2, znak3, znak4 from Znaki where № = '+IntToStr(nomer);
Q.Open;
znak1:=Q.Fields.Fields[0].AsInteger;
znak2:=Q.Fields.Fields[1].AsInteger;
znak3:=Q.Fields.Fields[2].AsInteger;
znak4:=Q.Fields.Fields[3].AsInteger;
if znak1 = 0 then LC10.Caption:=Chr(8804)+' 0' // Chr(8805)
else LC10.Caption:=Chr(8805)+' 0';
if znak2 = 0 then LC20.Caption:=Chr(8804)+' 0'
else LC20.Caption:=Chr(8805)+' 0';
if znak3 = 0 then LC30.Caption:=Chr(8804)+' 0'
else LC30.Caption:=Chr(8805)+' 0';
if znak4 = 0 then LC40.Caption:=Chr(8804)+' 0'
else LC40.Caption:=Chr(8805)+' 0';
end;
end;
procedure TFMain.EVarChange(Sender: TObject);
begin
with FMain do
begin
Zapoln();
//-----------------------------------------------------------------------------------------------------//
with LFxy do
begin
Caption:='F(x,y)=';
Caption:=Caption+ZnakN(a,'x'+Chr(178));
Caption:=Caption+Znak(2*b,'xy');
Caption:=Caption+Znak(c,'y'+Chr(178));
Caption:=Caption+Znak(2*d,'x');
Caption:=Caption+Znak(2*e,'y');
Caption:=Caption+ZnakKon(f);
end;
//-----------------------------------------------------------------------------------------------------//
LC1.Caption:=ZnakN(Am[1,1],'x')+Znak(Am[1,2],'y')+ZnakKon(Bm[1]);
LC2.Caption:=ZnakN(Am[2,1],'x')+Znak(Am[2,2],'y')+ZnakKon(Bm[2]);
LC3.Caption:=ZnakN(Am[3,1],'x')+Znak(Am[3,2],'y')+ZnakKon(Bm[3]);
LC4.Caption:=ZnakN(Am[4,1],'x')+Znak(Am[4,2],'y')+ZnakKon(Bm[4]);
ZnakConstrain();
end;
end;
procedure TFMain.FormCreate(Sender: TObject);
var FileName, ConStr:String;
begin
FileName:='variants.mdb';//EFileName.Text; //
try
Conn.Connected:= false;
Conn.ConnectionString :=
'Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source='+getCurrentDir+'\'+FileName+';'+
'Mode=Share Deny None;Extended Properties="";Jet OLEDB:System database="";Jet OLEDB:Registry Path="";'+
'Jet OLEDB:Database Password="";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;'+
'Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="";Jet OLEDB:Create System Database=False;'+
'Jet OLEDB:Encrypt Database=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False';
Conn.Connected:= true;
Conn.Open;
DBGMain.DataSource:=DSMain;
DataSetMain.Active:= false;
DataSetMain.CommandText :='select * from Варианты order by №';
DataSetMain.Active:= true;
DataSetMain.Open;
except
ShowMessage('Не удалось подключиться к базе вариантов. Вложите базу "variants.mdb" с вариантами в папку с программой.');
end;
//--------------------------------------------------------------------
ZnakConstrain();
//--------------------------------------------------------------------
Ris;
end;
Function Znak0(str : String) : String;
begin
if str = Chr(8804)+' 0' then Result:= Chr(8805)+' 0'
else Result:= Chr(8804)+' 0';
end;
Function ZnakUpdate(str : String) : Integer;
begin
if str = Chr(8804)+' 0' then Result:= 0
else Result:= 1;
end;
procedure TFMain.LC10Click(Sender: TObject);
begin
LC10.Caption:=Znak0(LC10.Caption);
end;
procedure TFMain.LC20Click(Sender: TObject);
begin
LC20.Caption:=Znak0(LC20.Caption);
end;
procedure TFMain.LC30Click(Sender: TObject);
begin
LC30.Caption:=Znak0(LC30.Caption);
end;
procedure TFMain.LC40Click(Sender: TObject);
begin
LC40.Caption:=Znak0(LC40.Caption);
end;
procedure TFMain.SaveZnakClick(Sender: TObject);
Var zi:Integer;
begin
with FMain do
try
nomer:=StrToInt(EVar.Text);
znak1:=ZnakUpdate(LC10.Caption);
znak2:=ZnakUpdate(LC20.Caption);
znak3:=ZnakUpdate(LC30.Caption);
znak4:=ZnakUpdate(LC40.Caption);
Q.Close;
Q.SQL.Text:='update Znaki set znak1='+IntToStr(znak1)
+', znak2='+IntToStr(znak2)
+', znak3='+IntToStr(znak3)
+', znak4='+IntToStr(znak4)
+' where №='+IntToStr(nomer);
Q.ExecSQL;
ShowMessage('Знаки успешно сохранены.');
except
ShowMessage('Не сохранить записать знаки.');
end;
end;
function RoundEx(chislo: double): double;
begin
RoundEx := (Round(chislo*1000))/1000;
end;
Function ZnakConst(str1, str2, str3 : String; X, Y :Double) : Integer;
Var zn1, zn2, zn3:Integer;
begin
zn1:=0; zn2:=0; zn3:=0;
if ((str1 = Chr(8804)+' 0') and (RoundEx(Am[1,1]*X+Am[1,2]*Y+Bm[1]) <= 0)) or
((str1 = Chr(8805)+' 0') and (RoundEx(Am[1,1]*X+Am[1,2]*Y+Bm[1]) >= 0)) then zn1:=1;
if ((str2 = Chr(8804)+' 0') and (RoundEx(Am[2,1]*X+Am[2,2]*Y+Bm[2]) <= 0)) or
((str2 = Chr(8805)+' 0') and (RoundEx(Am[2,1]*X+Am[2,2]*Y+Bm[2]) >= 0)) then zn2:=1;
if ((str3 = Chr(8804)+' 0') and (RoundEx(Am[3,1]*X+Am[3,2]*Y+Bm[3]) <= 0)) or
Страницы: 1, 2, 3, 4, 5, 6, 7, 8