Navigation

  • index
  • symbols |
  • next |
  • previous |
  • API for MATLAB 11.0.28 »
  • 7 Optimization Tutorials »
  • 7.2 A gallery of conic examples

7.2 A gallery of conic examples¶

In this chapter we demonstrate various simple examples of conic problems including various cone types (domains). We assume full familiarity with the basic tutorial of Sec. 7.1 (The conic interface tutorial).

7.2.1 Example CQO1 (quadratic cones)¶

We solve the conic quadratic problem:

(7.5)¶\[\begin{split}\begin{array}{ll} \minimize & y_1 + y_2 + y_3 \\ \st & x_1 + x_2 + 2.0 x_3 = 1.0,\\ & x_1,x_2,x_3 \geq 0.0,\\ & (y_1,x_1,x_2) \in \Q^3,\\ & (y_2,y_3,x_3) \in \Qr^3. \end{array}\end{split}\]

The variable has length 6 and is ordered as \(x\) followed by \(y\) from (7.5). We add the constraints in the order in which they appear above.

Listing 7.5 Source code solving problem (7.5). Click here to download.¶
    model = mosekmodel(...
        name = "cqo1", ...
        numvar = 6);

    % Variable is [x, y]
    model.objective("minimize", [0 0 0 1 1 1]');

    % Linear constraint
    model.appendcons(F = [1 1 2 0 0 0], domain = mosekdomain("eq", rhs=1.0));
    
    % Bounds on x
    model.appendcons(F = sparse([eye(3) zeros(3)]), domain = mosekdomain("rplus", dim=3));

    % Quadratic cone
    model.appendcons(F = sparse([1,2,3],[4,1,2],[1,1,1]), domain = mosekdomain("qcone",dim=3));
    
    % Rotated quadratic cone
    model.appendcons(F = sparse([1,2,3],[5,6,3],[1,1,1]), domain = mosekdomain("rqcone",dim=3));

    model.solve();
    if model.hassolution("interior")
        [xx,prosta,solsta] = model.getsolution("interior","x");
        fprintf("Solution x1,x2,x3: [ %s ]\n", sprintf("%.2g ", xx(1:3)));
        fprintf("Solution y1,y2,y3: [ %s ]\n", sprintf("%.2g ", xx(4:6)));
    end

7.2.2 Example AFFCO2 (power cones and auxiliary variables)¶

Consider the following simple optimization problem:

(7.6)¶\[\begin{split}\begin{array} {lrcl} \mbox{maximize} & x_1^{1/3} + (x_1+x_2+0.1)^{1/4} & & \\ \mbox{subject to} & (x_1-0.5)^2+(x_2-0.6)^2 & \leq & 1, \\ & x_1 - x_2 & \leq & 1. \end{array}\end{split}\]

Adding auxiliary variables we convert this problem into an equivalent conic form:

(7.7)¶\[\begin{split}\begin{array} {lrcl} \mbox{maximize} & t_1+t_2 & & \\ \mbox{subject to} & (1,x_1-0.5,x_2-0.6) & \in & \Q^3, \\ & (x_1,1,t_1) & \in & \POW_3^{(1/3,2/3)}, \\ & (x_1+x_2+0.1,1,t_2) & \in & \POW_3^{(1/4,3/4)}, \\ & x_1-x_2 & \leq & 1. \end{array}\end{split}\]

We arrange the variables as x followed by t.

For the sake of demonstration:

  • we add constraints in three blocks: first the quadratic constraint, then both power cone constraints together, and finally the linear constraint,

  • we add the quadratic constraint in the constructor mosekmodel and the other ones later using mosekmodel.appendcons,

while of course any other combination is also possible.

For example, the constraint \((1,x_1-0.5,x_2-0.6)\in \Q^3\) is written in matrix form as

\[\begin{split}\left[\begin{array}{cccc}0&0&0&0\\1&0&0&0\\0&1&0&0\end{array}\right] \left[\begin{array}{c}x_1\\x_2\\t_1\\t_2\end{array}\right] + \left[\begin{array}{c}1\\-0.5\\-0.6\end{array}\right] \in \Q^3.\end{split}\]

The joint power cone constraints have the following representation:

\[\begin{split}\left[\begin{array}{cccc}1&0&0&0\\0&0&0&0\\0&0&1&0\\1&1&0&0\\0&0&0&0\\0&0&0&1\end{array}\right] \left[\begin{array}{c}x_1\\x_2\\t_1\\t_2\end{array}\right] + \left[\begin{array}{c}0\\1\\0\\0.1\\1\\0\end{array}\right] \in \POW_3^{(1/3,2/3)}\times \POW^{(1/4,3/4)}_3.\end{split}\]

This is altogether implemented as follows:

Listing 7.6 Script implementing conic version of problem (7.6). Click here to download.¶
   % Variables [x1; x2; t1; t2]
   model = mosekmodel(name = "affco1", numvar = 4, ...
                      objsense = "maximize", objective = [0, 0, 1, 1], ...
                      F = sparse([zeros(1,4); speye(2) zeros(2,2)]), ...    % The quadratic cone constraint
                      g = [1 -0.5 -0.6]', ...
                      domain = mosekdomain("qcone", dim = 3));

   % The power cones added as one block:
   model.appendcons(name="pow", ...
                    F = sparse([1,3,4,4,6], [1,3,1,2,4], ones(1,5)), ...
                    g = [0 1 0 0.1 1 0]', ...
                    domain = [mosekdomain("pow", dim = 3, alpha = [1 2]'), ...     % Exponents [ 1/3, 2/3 ]
                              mosekdomain("pow", dim = 3, alpha = 0.25) ]);        % Exponents [ 0.25, 0.75 ]

   % Linear inequality x_1 - x_2 <= 1
   model.appendcons(F = [1 -1 0 0], domain = mosekdomain("less than", rhs = 1));

7.2.3 Example AFFCO2 (many exponential cones)¶

Consider the following simple linear dynamical system. A point in \(\real^n\) moves along a trajectory given by \(z(t) = z(0)\exp(At)\), where \(z(0)\) is the starting position and \(A=\Diag(a_1,\ldots,a_n)\) is a diagonal matrix with \(a_i<0\). Find the time after which \(z(t)\) is within euclidean distance \(d\) from the origin. Denoting the coordinates of the starting point by \(z(0)=(z_1,\ldots,z_n)\) we can write this as an optimization problem in one variable \(t\):

\[\begin{split}\begin{array}{lrcl} \minimize & t & & \\ \st & \sqrt{\sum_i \left(z_i\exp(a_it)\right)^2} & \leq & d, \end{array}\end{split}\]

which can be cast into conic form as:

(7.8)¶\[\begin{split}\begin{array}{lrcl} \minimize & t & & \\ \st & (d,z_1y_1,\ldots,z_ny_n) & \in & \Q^{n+1},\\ & (y_i, 1, a_it) & \in & \EXP, \ i=1,\ldots,n, \end{array}\end{split}\]

with variable vector \(x=[t,y_1,\ldots,y_n]^T\).

We assemble all conic constraints in the form

\[Fx+g\in \Q^{n+1}\times(\EXP)^n.\]

For the conic quadratic constraint the affine conic representation is

\[\begin{split}\left[\begin{array}{cc}0&0_n^T\\0_n& \Diag(z_1,\ldots,z_n)\end{array}\right] \left[\begin{array}{c}t\\y\end{array}\right] + \left[\begin{array}{c}d\\0_n\end{array}\right] \in \Q^{n+1}.\end{split}\]

For the \(i\)-th exponential cone we have

\[\begin{split}\left[\begin{array}{cc}0&e_i^T\\0&0_n\\a_i&0_n\end{array}\right] \left[\begin{array}{c}t\\y\end{array}\right] + \left[\begin{array}{c}0\\1\\0\end{array}\right] \in \EXP,\end{split}\]

where \(e_i\) denotes a vector of length \(n\) with a single \(1\) in position \(i\). We assemble all those exponential cone desctiptions in one call to mosekmodel.appendcons, where the argument n denotes the number of cones.

Listing 7.7 Script implementing problem (7.8). Click here to download.¶
function t = firstHittingTime(n, z, a, d)

   % Variables [t, y1, ..., yn]
   model = mosekmodel(...
       name = "affco2", ...
       numvar = n + 1, ...
       objective = [1 zeros(1,n)], ...
       objsense = "minimize");

   model.varname([1], ["t"]);

   % Quadratic cone
   model.appendcons(F = diag([0; z]), ...
                    g = [d; zeros(n,1)], ...
                    domain = mosekdomain("qcone", dim = n + 1));

   % All exponential cones (their number is n)
   FExp = sparse([1:3:3*n    3:3:3*n], ...
                 [2:n+1      ones(1,n)], ...
                 [ones(1,n)  a']);
   gExp = repmat([0; 1; 0], n, 1);
   model.appendcons(F = FExp, g = gExp, ...
                    domain = mosekdomain("exp", dim = 3, n = n));

   % Solve and get solution
   model.solve();

   if model.hassolution("interior")
      [x, prosta, solsta] = model.getsolution("interior", "x");
      t = x(1);
   end

Logo

Table of Contents

  • 1 Introduction
  • 2 Contact Information
  • 3 License Agreement
  • 4 Installation
  • 5 Design Overview
  • 6 Solver Interaction Tutorials
  • 7 Optimization Tutorials
    • 7.1 The conic interface tutorial
    • 7.2 A gallery of conic examples
    • 7.3 Geometric Programming
    • 7.4 Integer Optimization
    • 7.5 Disjunctive constraints
    • 7.6 Retrieving infeasibility certificates
    • 7.7 The linear/simplex interface tutorial
    • 7.8 The linear/simplex warm-start tutorial
  • 8 Debugging Tutorials
  • 9 Case Studies
  • 10 Technical guidelines
  • 11 Problem Formulation and Solutions
  • 12 Optimizers
  • 13 API Reference
  • 14 Supported File Formats
  • 15 List of examples
  • 16 Interface changes
  • 17 Bibliography

Quick search

 

Download PDF

Modeling Cookbook

Cheatsheet

Navigation

  • index
  • symbols |
  • next |
  • previous |
  • API for MATLAB 11.0.28 »
  • 7 Optimization Tutorials »
  • 7.2 A gallery of conic examples
© Copyright 2025, MOSEK ApS. Last updated on Aug 25, 2025.