# secondordercone

Create second-order cone constraint

## Syntax

``socConstraint = secondordercone(A,b,d,gamma)``

## Description

The `secondordercone` function creates a second-order cone constraint representing the inequality

`$‖A\cdot x-b‖\le {d}^{T}\cdot x-\gamma$`

from the input matrices `A`, `b`, `d`, and `gamma`.

example

````socConstraint = secondordercone(A,b,d,gamma)` creates a second-order cone constraint object `socConstraint`.Solve problems with second-order cone constraints by using the `coneprog` function. To represent multiple cone constraints, pass an array of these constraints to `coneprog` as shown in the example Several Cone Constraints.```

## Examples

collapse all

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)`
```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*x-b) - d'*x % Near 0 when the constraint is active`
```ans = -2.5677e-08 ```

To set up a problem with several second-order cone constraints, create an array of constraint objects. To save time and memory, create the highest-index 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 ```

## Input Arguments

collapse all

Linear factor of the cone, specified as a real matrix. The number of columns in `A` must equal the number of elements in `d`, and the number of rows in `A` must equal the number of elements in `b`.

Example: `diag([1,1/2,0])`

Data Types: `double`

Center of the cone, specified as a real vector. The number of elements in `b` must equal the number of rows in `A`.

Example: `zeros(3,1)`

Data Types: `double`

Linear bound, specified as a real vector. The number of elements in `d` must equal the number of columns in `A`.

Example: `[0;0;1]`

Data Types: `double`

Bound, specified as a real scalar. Smaller values of `gamma` correspond to looser constraints.

Example: `-1`

Data Types: `double`

## Output Arguments

collapse all

Second-order cone constraint, returned as a `SecondOrderConeConstraint` object. Use this object as a constraint for the `coneprog` solver. If you have multiple cone constraints, pass a vector of constraints to `coneprog`; see Several Cone Constraints.