Hi Amin,

From the documentation, you need to additionally define the linear term for each of the quadratic constraints. This can be done by modifying the m.quadcon(i).q field.

Some sample code to solve your nonlinear system is below. It doesn't include an objective function.

% Define dataqrow = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3];qcol = [4, 5, 6, 7, 4, 5, 6, 7, 4, 5, 6, 7];qval = ones(12);lcol = [8, 9, 10, 11, 12, 13, 1, 1, 14, 15, 16, 17];lval = [-4, -4, -4, -4, -5, -5, 0, 0, -7, -7, -7, -7];rhs = [0, 0, 0, 0, 0, 0, 25, 15, 0, 0, 0, 0];n = 17;% Add quadratic constraintsfor i=1:length(qrow)    disp(i);    m.quadcon(i).Qrow = qrow(i);    m.quadcon(i).Qcol = qcol(i);    m.quadcon(i).Qval = qval(i);    m.quadcon(i).q = sparse(lcol(i), 1, lval(i), n, 1);    m.quadcon(i).rhs = rhs(i);    m.quadcon(i).sense = '=';    m.quadcon(i).name = sprintf('qcon%d', i);end% Add variable namesvnames = cell(n,1);for i=1:n    vnames{i} = sprintf('x%d', i);endm.varnames = vnames;% No linear constraintsm.A = sparse(0,n);% Solve model and display solutionparams.NonConvex = 2;result = gurobi(m, params);disp(result.x);

I hope this helps!

Eli

Thank you so much, Eli.

You solved my problem!

I still do not understand this line:

m.quadcon(i).q = sparse(lcol(i), 1, lval(i), n, 1);

Have a nice day!

Amin

Hi Amin,

Great, I'm glad that helped!

The $$q$$ field is the vector defining the linear term on the left-hand side of the quadratic constraint. For example, the linear term of the first constraint is $$-4 x_8$$, which we can write as $$q^\top x$$, where the 8th element of $$q$$ is $$-4$$, and all other elements of $$q$$ are zero. That line of code defines this vector in sparse form for each constraint; see the MATLAB documentation for more details about the "sparse" function.

Eli