Skip to content

Instantly share code, notes, and snippets.

@MariaLavrovskaya
Created October 18, 2021 09:07
Show Gist options
  • Save MariaLavrovskaya/aa1e44bd53f4086b8e910b33a47a8e96 to your computer and use it in GitHub Desktop.
Save MariaLavrovskaya/aa1e44bd53f4086b8e910b33a47a8e96 to your computer and use it in GitHub Desktop.
% Finding D
D = zeros(length(x));
for i = 1: length(x)
for j = 1:length(x)
D(i,j) = y(i)*y(j)*x(i, 1:2)*x(j, 1:2)';
end
end
% Objective function
F.f = @(x) 1/2*x'*D*x - x'*ones(length(x),1);
F.df = @(x) D*x - ones(length(x),1);
F.d2f = @(x) D;
% Equality constraint x^Ty = 0
% eqConstraint.A = diag(y');
eqConstraint.A = y';
eqConstraint.b = zeros(1,1);
% Inequality constraints
constraint2.f = @(x) [x-5*ones(length(x),1); -x];
constraint2.df = @(x) [diag(ones(length(x),1)'); diag(-ones(length(x),1)')];
% HessConst2(:,:,1:100) = HessConstC;
% HessConst2(:,:,101:200) = HessConstL;
constraint2.d2f = @(x) HessConstL;
% % Setting up a problem
ineqConstraint = constraint2;
lambda0 = ones(length(x)*2,1);% ensure: lambda > 0
x0 = 0.001*ones(length(x),1);
eqConstraint = eqConstraint;
nu0 = ones(1,1);
% nu0 = ones(100,1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment