I have a mixed integer quadratic problem and my objective function is as follows

$$\arg \min \operatorname{Var}(f(x),g(x)) + \operatorname{Var}(c(x),d(x)) + \cdots$$

where $f$, $g$, $c$ $d$ are linear functions and $Var$ indicates variance and $x$ is a vector of 3000 binary variables.

If I want to solve the problem with mixed integer quadratic solver in gurobi I have to define it in the following form:

$$\ x^T Q x + q^T x $$

as the problem is defined in a high level format and there are large set of variables and coefficients , I have no idea how to extract $Q$ and $q$

  • 1
    $\begingroup$ Is this question related to the others you have written lately? $\endgroup$
    – nicoguaro
    Commented Aug 31, 2015 at 19:15
  • $\begingroup$ yes it is ! I'm looking into different toolboxes and different methods of modeling the problem $\endgroup$ Commented Aug 31, 2015 at 23:31
  • 4
    $\begingroup$ You should notice that most of them are not complete questions. Instead of posting several questions please take the time to describe each question. Pay attention to comments and improve the text, otherwise is difficult for people to help you. $\endgroup$
    – nicoguaro
    Commented Aug 31, 2015 at 23:34
  • 1
    $\begingroup$ Also, instead of writing multiple similar question, it might be better to ask a single "high-level" question about the problem you want to solve, where you describe the problem and what you need in a solution in detail. $\endgroup$ Commented Sep 1, 2015 at 10:10

1 Answer 1


As answered elsewhere, for MATLAB you have things like CVX and YALMIP. In YALMIP, you would solve using something like (assuming you have defined function f and g)

x = binvar(n,1);
objective = var(f(x),g(x)) + ...

A suitable solver will be called (if f and g are linear operators it is a MIQP and if Gurobi is installed and visible on path it will be used)

If you simply want to export the numerical data ($Q$ etc), you could do


Note though, a MIQP with 3000 variables can easily be completely intractable for any solver.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.