Escolar Documentos
Profissional Documentos
Cultura Documentos
gl/znCEkr
Item [a]
Uma função foi implementada em Matlab, com o intuito de chegar se determinada solução para um
problema satisfazem as condições de KKT, dados os valores de e a função satisfyKKT() retorna lógico
TRUE se todas as três condições forem satisfeitas. A solução com multiplicadores de
Lagrange satisfaz as condições de KKT visto que e
Desta forma, o ponto fornecido resulta em uma condição de estacionariedade. Para determinar se é ponto
de mínimo, devemos calcular a matriz Hessiana
Cujo autovalores são , logo a matriz Hessiana é positiva-definida, sendo portanto, um ponto de
mínimo.
Item [b]
A figura abaixo mostra as curvas de nível do problema além de evidenciar o domínio viável dado pelas
restrições. O ponto em vermelho é a solução do problema .
Item [c]
O resultado é mostrado na Tabela 1, na última página
clc
close all
%Check Hessian
H = hessian( lagrangian(f,g), fvars );
syms x2 x1
f = 64 - 16*x2 - 32*x1;
g = [4*x1+2*x2-30;
x1+2*x2-6];
x0 = [0; 0];
delta = 2;
for i = 1 : 15
f_lin = linearize_fun(ffun, fgrad, fvars, x_i);
lb = x_i - ones(size(x_i)).*delta;
ub = x_i + ones(size(x_i)).*delta;
else
flag = false;
end
if ~flag % if rejected
delta = delta/2;
x_i = x_old;
end
end
end
%%
function f_lin = linearize_fun(fun, grad_fun, Xvars, x_i)
% Linearize nonlinear function fun at point x_i using the function's
% gradient (grad_fun)
fi = fun(x_i);
grad_fi = grad_fun(x_i);
f_lin = fi + transpose(grad_fi)*(Xvars - x_i);
end
%%
function grad = gradient_f(f, fvars)
grad = [];
for i = 1:length(f)
grad = [grad; gradient(f(i))];
end
end
%%
function L = numLagrangian(fval, gval, lambda)
L = fval + dot(-gval,lambda);
end
%%
function [cf, cr] = coeffs_fun(f, fvars)
% Return the coefficients of a symbolic function Example: if f = 3*x^2 +
% pi*y + z + 2 , the function will return A = [3, pi, 1] (Note that the
% function will try to preserve the order of the coefficients). The last
% coefficient (2) will not be inserted in the output since it is not
% multiplied by any variable. If f is an array of symbolic expressions, the
% output will be a matriz, in wich each row will correspond to the
% coefficients of an expression.
cf = []; cr = [];
for i = 1 : length(f)
children_f = children(f(i));
cf_i = [];
cr_i = [];
for j = 1: length(children_f)
coef_f = coeffs(children_f(j), fvars);
if isempty(symvar(children_f(j)))
cr_i = [cr_i, -coef_f];
elseif ~isempty(symvar(children_f(j)))
cf_i = [cf_i, coef_f];
end
end
cf = [cf; double(cf_i)];
cr = [cr; double(cr_i)];
end
end
Item [d]