Você está na página 1de 8

A resolução desta e das demais listas (implementação em Matlab) podem ser baixadas em

https://goo.gl/znCEkr

Exercício 1

[a]
O problema de otimização não linear com restrição é convertido por um problema sem restrição utilizando-
se da técnica dos multiplicadores de Lagrange. Escrevemos a Lagrangiana do sistema da seguinte forma:

[b]
Derivamos a função Lagrangiana com respeito as variáveis de projeto para obter o sistema de equações:

Para obter a solução resolvemos o sistema de equações;

E obtemos a seguinte solução:

Como o número de restrições é menor que o número de variáveis de projeto, verificamos a matriz Hessiana

Sendo a matriz Hessiana positiva definida, a solução satisfaz as condições de KKT, desta forma o ponto (1,2)
é o ponto de mínimo.

Exercício 2

[a]

[b]
function T = steepestDescent_ex2b()
% STEEPESTDESCENT2 implements the optimization method steepest descent
%% user inputs
syms x y r

g = x - y + 1;
f = x^2 + y^2 - 6*y;
x0 = [0, 0];
r = 16;

ffun = matlabFunction(f);
gfun = matlabFunction(g);

% stop criteria
EPSILON = 0.001;
MAX_ITER = 1000;

x = x0(1);
y = x0(2);

x_old = x;
y_old = y;

i = 1;

while ( true )

% compute the objective function


fval = ffun(x, y);
gval = gfun(x, y);

phival = phifun(fval, gval, r);

% compute the gradient


g_phi = grad_phi(x, y, gval, r);

% s
s_x = -g_phi(1);
s_y = -g_phi(2);

% compute the step


alpha_hat = ( s_y*(r*x - (r+1)*y+r+3) - s_x*(r*(x - y +1)+x) ) / ...
( -2*r*s_x*s_y+(r+1)*s_x^2+(r+1)*s_y^2 );

alpha_til = - ( (x*s_x+(y-3)*s_y) / (s_x^2+s_y^2) );

gval = gfun( (x + alpha_hat * s_x), (y + alpha_hat * s_y) );


if (gval < 0)
alpha = alpha_hat;
else
alpha = alpha_til;
end
% updates the table
T(i, :) = [x, y, fval, gval, phival, s_x, s_y, alpha];

% updates x values (design variables)


x = x + alpha*s_x;
y = y + alpha*s_y;

% increment i and stop if reached max iteration number


i = i + 1;

fval_new = ffun(x, y);


gval_new = gfun(x, y);

phival_new = phifun(fval_new, gval_new, r);

if ( ( i >= MAX_ITER ) || ( abs( phival_new - phival ) < EPSILON ) )


disp('Reached maximun number of iterations');
return;
end

end
end

%%
function phi = phifun(fval, gval, r)
if ( -gval >= 0 )
phi = fval + r * (-gval)^2;
else
phi = fval;
end
end

%%
function gphi = grad_phi(x, y, gval, r)

if ( -gval >= 0 )
gphi = [(x.*2.0+r.*(x.*2.0-y.*2.0+2.0)), (y.*2.0-r.*(x.*2.0-y.*2.0+2.0)-6.0)];
else
gphi = [ (x.*2.0) , (y.*2.0-6.0) ];
end

end

 
O algoritmo interrompe na 47ª iteração pois a variação de fica menor que o erro .

 
[c]
O código foi modificado de forma a atualizar o valor de (sendo este multiplicado por a cada iteração), os
valores são apresentados na tabela abaixo

O algoritmo atinge o critério de parada na sétima iteração, apresentando como


resultado o ponto . Nota-se que , ao elevar à uma taxa menor, o resultado se aproxima
mais do resultado real , por exemplo se multiplicarmos por a cada iteração obtemos os
seguintes valores

Exercício 3
 

[a]
function T = steepestDescent_ex3()
% STEEPESTDESCENT2 implements the optimization method steepest descent

%% user inputs
syms x y r

g = x - y + 1;
f = x^2 + y^2 - 6*y;
x0 = [0, 0];
r = 1/4;
lambda = 0;

ffun = matlabFunction(f);
gfun = matlabFunction(g);

% stop criteria
EPSILON = 0.001;
MAX_ITER = 1000;

x = x0(1);
y = x0(2);

x_old = x;
y_old = y;

i = 1;

while ( true )

% compute the objective function


fval = ffun(x, y);
gval = gfun(x, y);

phival = phifun(fval, gval, r, lambda);

% compute the gradient


g_phi = grad_phi(x, y, gval, r, lambda);

% s
s_x = -g_phi(1);
s_y = -g_phi(2);
% compute the step
alpha_hat = ( (s_x*(lambda - 2*(r*(x-y+1)+x)) + s_y*(-lambda+2*r*(x-y+1)-2*y+6)) / ...
(-4*r*s_x*s_y+2*(r+1)*s_x^2+2*(r+1)*s_y^2) );

alpha_til = - ((x*s_x+(y-3)*s_y) / (s_x^2+s_y^2));

gval = gfun( (x + alpha_hat * s_x), (y + alpha_hat * s_y) );


if ( gval < (lambda/(2*r)) )
alpha = alpha_hat;
else
alpha = alpha_til;
end

% updates x values (design variables)


x = x + alpha*s_x;
y = y + alpha*s_y;

fval_new = ffun(x, y);


gval_new = gfun(x, y);

phival_new = phifun(fval_new, gval_new, r, lambda);

% update lambda
lambda = max( (lambda - 2*r* gval_new), 0);

% update r
r = r * 4;

% updates the table


T(i, :) = [x, y, fval, gval, phival, s_x, s_y, alpha, lambda];

% increment i and stop if reached max iteration number


i = i + 1;
%
if ( ( i >= MAX_ITER ) || ( abs ((fval - phival)/fval) < 0.00050 ) )
disp('Reached maximun number of iterations or stop criteria was met');
return;
end

end
end

%%
function phi = phifun(fval, gval, r, lambda)
if ( ((lambda/(2*r))-gval) >= 0 )
phi = fval + r.* ((lambda/(2*r))-gval)^2;
else

phi = fval;
end
end

%%
function gphi = grad_phi(x, y, gval, r, lambda)

if ( ((lambda/(2*r))-gval) >= 0 )
gphi = [x.*2.0+r.*(x.*2.0-y.*2.0-lambda./r+2.0), ...
y.*2.0-r.*(x.*2.0-y.*2.0-lambda./r+2.0)-6.0];

else
gphi = [ (x.*2.0) , (y.*2.0-6.0) ];
end

end

[b]
A tabela abaixo mostra a comparação entre os resultados para os diferentes algoritmos. Nota-se que o
algoritmo Lagrangiano Aumentado apresenta o menor número de iterações além de retornar um ponto
ótimo mais preciso. Nota-se também que nos algoritmos numéricos as restrições permanecem
ligeiramente violadas. Como mostrado no item o ponto ótimo calculado pelos algoritmos pode ser
melhorado se o incremento da variável a cada iteração for baixo (contudo isso eleva o número de
iterações).

Você também pode gostar