Sunteți pe pagina 1din 8

Set de probleme rezolvate model pentru

OPTIMIZARE
Horvth Alexandru
Problema 1. Minimul/maximul local al unei funcii de o variabil
S se calculeze minimul funciei:
f(x) = x
4
3x
3
+ x
2
1,
pe intervalul [2, 3]. S se precizeze att valoarea minim ct i valoarea
argumentului n care funcia atinge aceast valoare minim!
Rezolvare
n editor se editeaz ierul fun.m
function y = fun(x)
y = x^4-3*x^3+x^2-1;
apoi se d comanda:
>> [xmin, fmin] = fminbnd(@fun,-2,3)
xmin =
2.0000
fmin =
-5.0000
Problema 2. Problem de programare liniar
S se calculeze maximul funciei f, unde
f(x, y, z) = 2x + 3y + 4z,
cu urmtoarele restricii asupra variabilelor:

x +y +z 7
2x y 2z 1
x +2y +3z 3
x, y, z 0.
S se precizeze att aceast valoare maxim ct i valoarea argumentelor n
care funcia atinge aceast valoare!
Rezolvare
>> f=-[2; 3; 4];
>> A=[1 1 1; -2 1 2; -1 2 3];
>> b=[ 7; 1; 3];
>> lb=zeros(3,1);
>> [xmax,fval] = linprog(f,A,b,[],[],lb);
Optimization terminated.
>> xmax
xmax =
4.5000
0.0000
2.5000
>> -fval
ans =
19.0000
Problema 3. Problem de programare ptratic
S se calculeze minimul funciei q, n vecintatea punctului (0, 0, 0), unde
q(x, y, z) = x
2
3xy yz + 2z
2
4z,
cu urmtoarele restricii asupra variabilelor:

x +y z 2
x +2y +z 3
2x y 3z 4.
S se precizeze att aceast valoare minim ct i valoarea argumentelor n
care funcia f atinge valoare sa minim!
Rezolvare
Se dau comenzile:
>> H=[1 -3/2 0; -3/2 0 -1/2; 0 -1/2 2];
>> f=[0; 0; -4];
>> A=[1 1 -1; -1 2 1; 2 -1 -3];
>> b=[2; 3; 4];
>> x0=zeros(3,1);
>> [xmin qmin]=quadprog(H,f,A,b,[],[],[],[],x0)
Warning: Large-scale algorithm does not currently solve this problem
formulation,
using medium-scale algorithm instead.
> In quadprog at 291
Optimization terminated.
xmin =
2.6667
1.6667
2.3333
qmin =
-8.9444
Problema 4. Problem de optimizare neliniar fr restricii
S se calculeze minimul funciei f, n vecintatea punctului (5, 0, 1), unde
f(x, y, z) = cos(x
3
+ 2 yz + 2xz) + sin(xy).
S se precizeze att aceast valoare minim ct i valoarea argumentelor n
care funcia f atinge valoare sa minim!
Rezolvare
n editor se editeaz ierul myfun.m
function f = myfun(x)
f=cos(x(1)^3+2*x(2)*x(3)+2*x(1)*x(3))+sin(x(1)*x(2));
Apoi se dau comenzile:
>> x0=[5; 0; -1];
>> [xmin fmin]=fminunc(@myfun,x0)
Warning: Gradient must be provided for trust-region algorithm;
using line-search algorithm instead.
> In fminunc at 347
Local minimum found.
Optimization completed because the size of the gradient is less than
the default value of the function tolerance.
<stopping criteria details>
xmin =
5.0083
-0.3136
-0.9993
fmin =
-2.0000
Problema 5. Problem de optimizare neliniar cu restricii
S se calculeze minimul funciei f, n vecintatea punctului (0, 0, 1), unde
f(x, y, z) = x
2
+ y
3
+ z
4
,
cu urmtoarele restricii asupra variabilelor:
{
2x
2
xy 5
x
3
y z = 1
S se precizeze att aceast valoare minim ct i valoarea argumentelor n
care funcia f atinge valoare sa minim!
Rezolvare
n editor se editeaz ierul myfun.m
function f = myfun(x)
f=x(1)^2+x(2)^3+x(3)^4; % Funcia obiectiv (de optimizat)
n editor se editeaz ierul mycon.m
function [c ceq] = mzcon( x )
c = 2*x(1)^2-x(1)*x(2)-5; % Inegaliti neliniare.
ceq=x(1)^3-x(2)-x(3)-1; % Egaliti neliniare.
Apoi se dau comenzile:
>> x0=zeros(3,1);
>> [xmin fmin]=fmincon(@f101,x0,[],[],[],[],[],[],@con101)
Warning: Trust-region-reflective algorithm does not solve this type of
problem, using active-set algorithm. You could also try the
interior-point or sqp algorithms: set the Algorithm option to
interior-point or sqp and rerun. For more help, see Choosing the
Algorithm in the documentation.
> In fmincon at 472
xmin =
-0.0000
-2.8085
1.8085
fmin =
-11.4552
Problema 6. Problem de transport
Trei depozite D
1
, D
2
i D
3
aprovizioneaz trei centre C
1
, C
2
, C
3
de consum.
Costul transportului pe tona de marf este: De la D
1
la cele trei centre 5, 6,
6 euro respectiv, de la D
2
5, 7, 8 euro respectiv, iar de la D
3
4, 5, 7 euro
respectiv. La depozitele D
1
, D
2
i D
3
se a respectiv 170, 280, 250 tone de
marf, iar centrele de consum C
1
, C
2
, C
3
120, 230, 250 tone respectiv.
S se ntocmeasc un plan de transport de cost minim.
Rezolvare
Se deseneaz graful problemei:
C1
C2
C3
120
230
250
D1
D2
D3
170
280
150
5
6
7
8
5
4
5
7
6
Se ntocmete tabelul:
Depozitul Centrul TOTAL
C1 C2 C3 Disponibil
D1 (5) x
11
(6) x
12
(6) x
13
170
D2 (5) x
21
(7) x
22
(8) x
23
280
D3 (4) x
31
(5) x
32
(7) x
33
150
TOTAL Necesar 120 230 250 600
Am ajuns la o problem de programare liniar.
Avem nevoie de minimul funciei f, unde
f(x
11
, x
12
, . . . , x
33
) = 5x
11
+6x
12
+6x
13
+5x
21
+7x
22
+8x
23
+4x
31
+5x
32
+7x
33
,
cu urmtoarele restricii asupra variabilelor:

x
11
+x
12
+x
13
= 170
x
21
+x
22
+x
23
= 280
x
31
+x
32
+x
33
= 150
x
11
+x
21
+x
31
= 120
x
11
+x
21
+x
31
= 230
x
11
+x
21
+x
31
= 250
unde toate variabilele sunt numere pozitive:
x
11
, x
12
, x
13
, x
21
, x
22
, x
23
, x
31
, x
32
, x
33
0.
Prin urmare se dau comenzile Matlab:
>> f=[5 6 6 5 7 8 4 5 7];
>> Aeq=[ 1 1 1 0 0 0 0 0 0; 0 0 0 1 1 1 0 0 0; 0 0 0 0 0 0 1 1 1;
1 0 0 1 0 0 1 0 0; 0 1 0 0 1 0 0 1 0; 0 0 1 0 0 1 0 0 1];
>> beq=[170 280 150 120 230 250];
>> lb=zeros(6,1);
>> [xmin fmin]=linprog(f,[],[],Aeq,beq,lb)
Optimization terminated.
xmin =
0.0000
0.0000
170.0000
136.0235
0.0000
143.9765
-16.0235
230.0000
-63.9765
fmin =
3.4900e+003

S-ar putea să vă placă și