coneprog
Secondorder cone programming solver
Syntax
Description
The coneprog
function is a secondorder cone programming
solver that finds the minimum of a problem specified by
$$\underset{x}{\mathrm{min}}{f}^{T}x$$
subject to the constraints
$$\begin{array}{c}\Vert {A}_{\text{sc}}(i)\cdot x{b}_{\text{sc}}(i)\Vert \le {d}_{\text{sc}}^{T}(i)\cdot x\gamma (i)\\ A\cdot x\le b\\ \text{Aeq}\cdot x=\text{beq}\\ \text{lb}\le x\le \text{ub}.\end{array}$$
f, x, b, beq,
lb, and ub are vectors, and A and
Aeq are matrices. For each i, the matrix
A_{sc}(i), vectors
d_{sc}(i) and
b_{sc}(i), and scalar
γ(i) are in a secondorder cone constraint that you
create using secondordercone
.
For more details about cone constraints, see SecondOrder Cone Constraint.
solves the secondorder cone programming problem with the constraints in
x
= coneprog(f
,socConstraints
)socConstraints
encoded as
A_{sc}(i) =
socConstraints(i).A
b_{sc}(i) =
socConstraints(i).b
d_{sc}(i) =
socConstraints(i).d
γ(i) =
socConstraints(i).gamma
Examples
Single Cone Constraint
To set up a problem with a secondorder cone constraint, create a secondorder 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)
Optimal solution found.
x = 3×1
0.4851
3.8806
2.0000
fval = 8.2462
The solution component x(3)
is at its upper bound. The cone constraint is active at the solution:
norm(A*xb)  d'*x % Near 0 when the constraint is active
ans = 2.5677e08
Several Cone Constraints
To set up a problem with several secondorder cone constraints, create an array of constraint objects. To save time and memory, create the highestindex constraint first.
A = diag([1,2,0]); b = zeros(3,1); d = [0;0;1]; gamma = 1; socConstraints(3) = secondordercone(A,b,d,gamma); A = diag([3,0,1]); d = [0;1;0]; socConstraints(2) = secondordercone(A,b,d,gamma); A = diag([0;1/2;1/2]); d = [1;0;0]; socConstraints(1) = secondordercone(A,b,d,gamma);
Create the linear objective function vector.
f = [1;2;4];
Solve the problem by using the coneprog
function.
[x,fval] = coneprog(f,socConstraints)
Optimal solution found.
x = 3×1
0.4238
1.6477
2.3225
fval = 13.0089
Cone Programming with Linear Constraints
Specify an objective function vector and a single secondorder cone constraint.
f = [4;9;2]; Asc = diag([1,4,0]); b = [0;0;0]; d = [0;0;1]; gamma = 0; socConstraints = secondordercone(Asc,b,d,gamma);
Specify a linear inequality constraint.
A = [1/4,1/9,1]; b = 5;
Solve the problem.
[x,fval] = coneprog(f,socConstraints,A,b)
Optimal solution found.
x = 3×1
3.2304
0.6398
4.1213
fval = 26.9225
Cone Programming with Nondefault Options
To observe the iterations of the coneprog
solver, set the Display
option to 'iter'
.
options = optimoptions('coneprog','Display','iter');
Create a secondorder cone programming problem and solve it using options
.
Asc = diag([1,1/2,0]); b = zeros(3,1); d = [0;0;1]; gamma = 0; socConstraints = secondordercone(Asc,b,d,gamma); f = [1,2,0]; Aineq = []; bineq = []; Aeq = []; beq = []; lb = [Inf,Inf,0]; ub = [Inf,Inf,2]; [x,fval] = coneprog(f,socConstraints,Aineq,bineq,Aeq,beq,lb,ub,options)
Iter Fval Primal Infeas Dual Infeas Duality Gap Time 1 0.000000e+00 0.000000e+00 5.714286e01 1.250000e01 0.03 2 7.558066e+00 0.000000e+00 7.151114e02 1.564306e02 0.04 3 7.366973e+00 0.000000e+00 1.075440e02 2.352525e03 0.05 4 8.243432e+00 0.000000e+00 5.191882e05 1.135724e05 0.05 5 8.246067e+00 1.387779e17 2.430813e06 5.317403e07 0.05 6 8.246211e+00 0.000000e+00 6.154504e09 1.346298e09 0.05 Optimal solution found.
x = 3×1
0.4851
3.8806
2.0000
fval = 8.2462
Cone Programming with Problem Structure
Create the elements of a secondorder cone programming problem. To save time and memory, create the highestindex constraint first.
A = diag([1,2,0]); b = zeros(3,1); d = [0;0;1]; gamma = 1; socConstraints(3) = secondordercone(A,b,d,gamma); A = diag([3,0,1]); d = [0;1;0]; socConstraints(2) = secondordercone(A,b,d,gamma); A = diag([0;1/2;1/2]); d = [1;0;0]; socConstraints(1) = secondordercone(A,b,d,gamma); f = [1;2;4]; options = optimoptions('coneprog','Display','iter');
Create a problem structure with the required fields, as described in problem.
problem = struct('f',f,... 'socConstraints',socConstraints,... 'Aineq',[],'bineq',[],... 'Aeq',[],'beq',[],... 'lb',[],'ub',[],... 'solver','coneprog',... 'options',options);
Solve the problem by calling coneprog
.
[x,fval] = coneprog(problem)
Iter Fval Primal Infeas Dual Infeas Duality Gap Time 1 0.000000e+00 0.000000e+00 5.333333e01 5.555556e02 0.18 2 9.696012e+00 1.850372e17 7.631901e02 7.949897e03 0.20 3 1.178942e+01 9.251859e18 1.261803e02 1.314378e03 0.20 4 1.294426e+01 1.850372e17 1.683078e03 1.753206e04 0.20 5 1.295217e+01 1.850372e17 8.994595e04 9.369370e05 0.21 6 1.295331e+01 1.850372e17 4.748841e04 4.946709e05 0.21 7 1.300753e+01 9.251859e18 2.799942e05 2.916606e06 0.21 8 1.300671e+01 9.251859e18 2.366136e05 2.464725e06 0.21 9 1.300850e+01 1.850372e17 8.187205e06 8.528338e07 0.21 10 1.300843e+01 4.625929e18 7.326330e06 7.631594e07 0.21 11 1.300862e+01 9.251859e18 2.707005e06 2.819797e07 0.21 12 1.300892e+01 0.000000e+00 9.204457e08 9.587976e09 0.22 Optimal solution found.
x = 3×1
0.4238
1.6477
2.3225
fval = 13.0089
Examine coneprog
Solution Process
Create a secondorder cone programming problem. To save time and memory, create the highestindex constraint first.
A = diag([1,2,0]); b = zeros(3,1); d = [0;0;1]; gamma = 1; socConstraints(3) = secondordercone(A,b,d,gamma); A = diag([3,0,1]); d = [0;1;0]; socConstraints(2) = secondordercone(A,b,d,gamma); A = diag([0;1/2;1/2]); d = [1;0;0]; socConstraints(1) = secondordercone(A,b,d,gamma); f = [1;2;4]; options = optimoptions('coneprog','Display','iter'); A = []; b = []; Aeq = []; beq = []; lb = []; ub = [];
Solve the problem, requesting information about the solution process.
[x,fval,exitflag,output] = coneprog(f,socConstraints,A,b,Aeq,beq,lb,ub,options)
Iter Fval Primal Infeas Dual Infeas Duality Gap Time 1 0.000000e+00 0.000000e+00 5.333333e01 5.555556e02 0.03 2 9.696012e+00 5.551115e17 7.631901e02 7.949897e03 0.03 3 1.178942e+01 3.700743e17 1.261803e02 1.314378e03 0.03 4 1.294426e+01 1.850372e17 1.683078e03 1.753206e04 0.03 5 1.295217e+01 9.251859e18 8.994595e04 9.369370e05 0.03 6 1.295331e+01 9.251859e18 4.748841e04 4.946709e05 0.03 7 1.300753e+01 9.251859e18 2.799942e05 2.916606e06 0.03 8 1.300671e+01 9.251859e18 2.366136e05 2.464725e06 0.04 9 1.300850e+01 9.251859e18 8.222244e06 8.564838e07 0.04 10 1.300843e+01 1.850372e17 7.318333e06 7.623264e07 0.04 11 1.300865e+01 9.251859e18 2.636568e06 2.746425e07 0.04 12 1.300892e+01 1.850372e17 3.407939e08 3.549936e09 0.04 Optimal solution found.
x = 3×1
0.4238
1.6477
2.3225
fval = 13.0089
exitflag = 1
output = struct with fields:
iterations: 12
primalfeasibility: 1.8504e17
dualfeasibility: 3.4079e08
dualitygap: 3.5499e09
algorithm: 'interiorpoint'
linearsolver: 'augmented'
message: 'Optimal solution found.'
Both the iterative display and the output structure show that
coneprog
used 12 iterations to arrive at the solution.The exit flag value
1
and theoutput.message
value'Optimal solution found.'
indicate that the solution is reliable.The
output
structure shows that the infeasibilities tend to decrease through the solution process, as does the duality gap.You can reproduce the
fval
output by multiplyingf'*x
.
f'*x
ans = 13.0089
Obtain coneprog
Dual Variables
Create a secondorder cone programming problem. To save time and memory, create the highestindex constraint first.
A = diag([1,2,0]); b = zeros(3,1); d = [0;0;1]; gamma = 1; socConstraints(3) = secondordercone(A,b,d,gamma); A = diag([3,0,1]); d = [0;1;0]; socConstraints(2) = secondordercone(A,b,d,gamma); A = diag([0;1/2;1/2]); d = [1;0;0]; socConstraints(1) = secondordercone(A,b,d,gamma); f = [1;2;4];
Solve the problem, requesting dual variables at the solution along with all other coneprog
output..
[x,fval,exitflag,output,lambda] = coneprog(f,socConstraints);
Optimal solution found.
Examine the returned lambda
structure. Because the only problem constraints are cone constraints, examine only the soc
field in the lambda
structure.
disp(lambda.soc)
1.0e05 * 0.0879 0.3002 0.0589
The constraints have nonzero dual values, indicating the constraints are active at the solution.
Input Arguments
f
— Coefficient vector
real vector  real array
Coefficient vector, specified as a real vector or real array. The coefficient vector
represents the objective function f'*x
. The notation assumes that
f
is a column vector, but you can use a row vector or array.
Internally, coneprog
converts f
to the column
vector f(:)
.
Example: f = [1,3,5,6]
Data Types: double
socConstraints
— Secondorder cone constraints
vector of SecondOrderConeConstraint
objects
Secondorder cone constraints, specified as vector of SecondOrderConeConstraint
objects. Create these objects using the secondordercone
function.
socConstraints
encodes the constraints
$$\Vert {A}_{\text{sc}}(i)\cdot x{b}_{\text{sc}}(i)\Vert \le {d}_{\text{sc}}^{T}(i)\cdot x\gamma (i)$$
where the mapping between the array and the equation is as follows:
A_{sc}(i) =
socConstraints.A(i)
b_{sc}(i) =
socConstraints.b(i)
d_{sc}(i) =
socConstraints.d(i)
γ(i) =
socConstraints.gamma(i)
Example: Asc = diag([1 1/2 0]); bsc = zeros(3,1); dsc = [0;0;1]; gamma = 1;
socConstraints = secondordercone(Asc,bsc,dsc,gamma);
Data Types: struct
A
— Linear inequality constraints
real matrix
Linear inequality constraints, specified as a real matrix. A
is an M
byN
matrix, where M
is the number of inequalities, and N
is the number of variables (length of f
). For large problems, pass A
as a sparse matrix.
A
encodes the M
linear inequalities
A*x <= b
,
where x
is the column vector of N
variables x(:)
, and b
is a column vector with M
elements.
For example, consider these inequalities:
x_{1} +
2x_{2} ≤
10
3x_{1} +
4x_{2} ≤
20
5x_{1} +
6x_{2} ≤ 30.
Specify the inequalities by entering the following constraints.
A = [1,2;3,4;5,6]; b = [10;20;30];
Example: To specify that the xcomponents add up to 1 or less, take A =
ones(1,N)
and b = 1
.
Data Types: double
b
— Linear inequality constraints
real vector
Linear inequality constraints, specified as a real vector. b
is
an M
element vector related to the A
matrix.
If you pass b
as a row vector, solvers internally
convert b
to the column vector b(:)
.
For large problems, pass b
as a sparse vector.
b
encodes the M
linear
inequalities
A*x <= b
,
where x
is the column vector of N
variables x(:)
,
and A
is a matrix of size M
byN
.
For example, consider these inequalities:
x_{1}
+ 2x_{2} ≤
10
3x_{1}
+ 4x_{2} ≤
20
5x_{1}
+ 6x_{2} ≤
30.
Specify the inequalities by entering the following constraints.
A = [1,2;3,4;5,6]; b = [10;20;30];
Example: To specify that the x components sum to 1 or less, use A =
ones(1,N)
and b = 1
.
Data Types: double
Aeq
— Linear equality constraints
real matrix
Linear equality constraints, specified as a real matrix. Aeq
is an Me
byN
matrix, where Me
is the number of equalities, and N
is the number of variables (length of f
). For large problems, pass Aeq
as a sparse matrix.
Aeq
encodes the Me
linear equalities
Aeq*x = beq
,
where x
is the column vector of N
variables x(:)
, and beq
is a column vector with Me
elements.
For example, consider these equalities:
x_{1} +
2x_{2} +
3x_{3} =
10
2x_{1} +
4x_{2} +
x_{3} = 20.
Specify the equalities by entering the following constraints.
Aeq = [1,2,3;2,4,1]; beq = [10;20];
Example: To specify that the xcomponents sum to 1, take Aeq = ones(1,N)
and
beq = 1
.
Data Types: double
beq
— Linear equality constraints
real vector
Linear equality constraints, specified as a real vector. beq
is
an Me
element vector related to the Aeq
matrix.
If you pass beq
as a row vector, solvers internally
convert beq
to the column vector beq(:)
.
For large problems, pass beq
as a sparse vector.
beq
encodes the Me
linear
equalities
Aeq*x = beq
,
where x
is the column vector of N
variables
x(:)
, and Aeq
is a matrix of size
Me
byN
.
For example, consider these equalities:
x_{1}
+ 2x_{2} +
3x_{3} =
10
2x_{1}
+ 4x_{2} +
x_{3} =
20.
Specify the equalities by entering the following constraints.
Aeq = [1,2,3;2,4,1]; beq = [10;20];
Example: To specify that the x components sum to 1, use Aeq = ones(1,N)
and
beq = 1
.
Data Types: double
lb
— Lower bounds
real vector  real array
Lower bounds, specified as a real vector or real array. If the length of
f
is equal to the length of lb
, then
lb
specifies that
x(i) >= lb(i)
for all i
.
If numel(lb) < numel(f)
, then lb
specifies that
x(i) >= lb(i)
for 1 <= i <= numel(lb)
.
In this case, solvers issue a warning.
Example: To specify that all xcomponents are positive, use lb =
zeros(size(f))
.
Data Types: double
ub
— Upper bounds
real vector  real array
Upper bounds, specified as a real vector or real array. If the length of
f
is equal to the length of ub
, then
ub
specifies that
x(i) <= ub(i)
for all i
.
If numel(ub) < numel(f)
, then ub
specifies that
x(i) <= ub(i)
for 1 <= i <= numel(ub)
.
In this case, solvers issue a warning.
Example: To specify that all xcomponents are less than 1
, use ub =
ones(size(f))
.
Data Types: double
options
— Optimization options
output of optimoptions
Optimization options, specified as the output of
optimoptions
.
Option  Description 

ConstraintTolerance  Feasibility tolerance for constraints, a scalar from

 Level of display (see Iterative Display):

LinearSolver  Algorithm for solving one step in the iteration:
If
For a sparse example, see Compare Speeds of coneprog Algorithms. 
 Maximum number of iterations allowed, a positive integer. The default
is See Tolerances and Stopping Criteria and Iterations and Function Counts. 
MaxTime  Maximum amount of time in seconds that the algorithm runs, a positive
number or 
 Termination tolerance on the dual feasibility, a positive scalar. The
default is 
Example: optimoptions('coneprog','Display','iter','MaxIterations',100)
problem
— Problem structure
structure
Problem structure, specified as a structure with the following fields.
Field Name  Entry 

 Linear objective function vector f 
 Structure array of secondorder cone constraints 
 Matrix of linear inequality constraints 
 Vector of linear inequality constraints 
 Matrix of linear equality constraints 
 Vector of linear equality constraints 
lb  Vector of lower bounds 
ub  Vector of upper bounds 
 'coneprog' 
 Options created with optimoptions 
Data Types: struct
Output Arguments
fval
— Objective function value at the solution
real number
Objective function value at the solution, returned as a real number. Generally,
fval
= f'*x
. The fval
output
is empty when the exitflag
value is –2
,
–3
, or –10
.
exitflag
— Reason coneprog
stopped
integer
Reason coneprog
stopped, returned as an integer.
Value  Description 

 The function converged to a solution

 The number of iterations exceeded

 No feasible point was found. 
 The problem is unbounded. 
 The search direction became too small. No further progress could be made. 
 The problem is numerically unstable. 
Tip
If you get exit flag 0
, 7
, or
10
, try using a different value of the
LinearSolver
option.
output
— Information about optimization process
structure
Information about the optimization process, returned as a structure with these fields.
Field  Description 

algorithm  Optimization algorithm used 
dualfeasibility  Maximum of dual constraint violations 
dualitygap  Duality gap 
iterations  Number of iterations 
message  Exit message 
primalfeasibility  Maximum of constraint violations 
linearsolver  Internal step solver algorithm used 
The output
fields dualfeasibility
,
dualitygap
, and primalfeasibility
are empty when
the exitflag
value is –2, –3, or –10.
lambda
— Dual variables at the solution
structure
Dual variables at the solution, returned as a structure with these fields.
Field  Description 

lower  Lower bounds corresponding to 
upper  Upper bounds corresponding to 
ineqlin  
eqlin  
soc  Secondorder cone constraints corresponding to
socConstraints 
lambda
is empty ([]
) when the
exitflag
value is –2
, –3
,
or –10
.
The Lagrange multipliers (dual variables) are part of the following Lagrangian, which is stationary (zero gradient) at a solution:
$$\begin{array}{l}{f}^{T}x+{\displaystyle \sum _{i}{\lambda}_{\text{soc}}(i)\left({d}_{\text{soc}}^{T}(i)x\text{gamma}(i)\Vert {A}_{\text{soc}}(i)x{b}_{\text{soc}}(i)\Vert \right)}\\ \text{}+{\lambda}_{\text{ineqlin}}^{T}\left(bAx\right)\text{\hspace{0.05em}}+{\lambda}_{\text{eqlin}}^{T}\left(\text{Aeq}\text{\hspace{0.17em}}x\text{beq}\right)+{\lambda}_{\text{upper}}^{T}\left(\text{ub}x\right)+{\lambda}_{\text{lower}}^{T}\left(x\text{lb}\right).\end{array}$$
The inequality terms that multiply the lambda
fields are
nonnegative.
More About
SecondOrder Cone Constraint
Why is the constraint
$$\Vert A\cdot xb\Vert \le {d}^{T}\cdot x\gamma $$
called a secondorder cone constraint? Consider a cone in 3D space with elliptical crosssections in the xy plane, and a diameter proportional to the z coordinate. The y coordinate has scale ½, and the x coordinate has scale 1. The inequality defining the inside of this cone with its point at [0,0,0] is
$$\sqrt{{x}^{2}+\frac{{y}^{2}}{4}}\le z.$$
In the coneprog
syntax, this cone has the following
arguments.
A = diag([1 1/2 0]); b = [0;0;0]; d = [0;0;1]; gamma = 0;
Plot the boundary of the cone.
[X,Y] = meshgrid(2:0.1:2); Z = sqrt(X.^2 + Y.^2/4); surf(X,Y,Z) view(8,2) xlabel 'x' ylabel 'y' zlabel 'z'
The b
and gamma
arguments move the cone. The
A
and d
arguments rotate the cone and change its
shape.
Algorithms
The algorithm uses an interiorpoint method. For details, see SecondOrder Cone Programming Algorithm.
Alternative Functionality
App
The Optimize Live Editor task provides a visual interface for coneprog
.
Version History
Introduced in R2020bR2021a: Two coneprog
lambda
Structures Renamed
Behavior changed in R2021a
The coneprog
lambda
output
argument fields lambda.eq
and lambda.ineq
have been
renamed to lambda.eqlin
and lambda.ineqlin
,
respectively. This change causes the coneprog
lambda
structure fields to have the same names as the corresponding
fields in other solvers.
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
 América Latina (Español)
 Canada (English)
 United States (English)
Europe
 Belgium (English)
 Denmark (English)
 Deutschland (Deutsch)
 España (Español)
 Finland (English)
 France (Français)
 Ireland (English)
 Italia (Italiano)
 Luxembourg (English)
 Netherlands (English)
 Norway (English)
 Österreich (Deutsch)
 Portugal (English)
 Sweden (English)
 Switzerland
 United Kingdom (English)