solve system of nonlinear equations+Matlab
Hello, Good day. I am a newbie in Gurobie and I would be grateful if you can help me with this question that I try to sole in Matlab.
I have a nonlinear system of equations and a constraint to minimize each variable:
There are 12 equations and 17 variables{x(1),x(2),...,x(17)}.
If variables x(8),...,x(17) are constant numbers, I can use the same approach in "bilinear.m" example and solve it. But for this case, I cannot find a solution.
Thank you in advance,
Amin

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 data
qrow = [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 constraints
for 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 names
vnames = cell(n,1);
for i=1:n
vnames{i} = sprintf('x%d', i);
end
m.varnames = vnames;
% No linear constraints
m.A = sparse(0,n);
% Solve model and display solution
params.NonConvex = 2;
result = gurobi(m, params);
disp(result.x);I hope this helps!
Eli

Hi Amin,
Great, I'm glad that helped!
The \( q \) field is the vector defining the linear term on the lefthand 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
Please sign in to leave a comment.
Comments
3 comments