%% Single Cone Constraint
% To set up a problem with a second-order cone constraint, create a second-order cone constraint object.

A = diag([1,1/2,0]);
b = zeros(3,1);
d = [0;0;1];
gamma = 0;
socConstraints = secondordercone(A,b,d,gamma);

% Create an objective function vector.

f = [-1,-2,0];

% The problem has no linear constraints. Create empty matrices for these constraints.

Aineq = [];
bineq = [];
Aeq = [];
beq = [];

% Set upper and lower bounds on x(3).

lb = [-Inf,-Inf,0];
ub = [Inf,Inf,2];

% Solve the problem by using the coneprog function.

[x,fval] = coneprog(f,socConstraints,Aineq,bineq,Aeq,beq,lb,ub)

% The solution component x(3) is at its upper bound. The cone constraint is active at the solution:

norm(A*x-b) - d'*x % Near 0 when the constraint is active

% Copyright 2020 The MathWorks, Inc.