Hi Prof. Johan.
I'm solving a nonlinear problem with yalmip in Matlab, and different solvers, gurobi & ipopt, are used separately. However, the solution is quiet different. I use python+gurobi to checkout which solution is correct (as I think is correct), the solution from py+gurobi is the same as the one ipopt solves. I doubt why this happens, and I hope to get your help, thank you.
The following is the code in Matlab.
clear
clc
tic
close all;
yalmip('clear')
%% ------------------------------- %%
%% Define a variable
%% ------------------------------- %%
x = sdpvar(5,1);
sdpvar Profit;
%% ------------------------------- %%
%% The constraints
%% ------------------------------- %%
Constraints = [
x >= 0
x(1)+x(2)^2-2 == 0;
x(2)+2*x(3)^2-3 == 0;
x(1)^2 - x(2) + x(3)^2 >= 0;
x(1) + x(2)^2 + x(4)*x(5) <=20;
x(4) == log(x(3));
x(5) == x(3)*x(3);
];
%% ------------------------------- %%
%% My objective
%% ------------------------------- %%
Constraints = [Constraints,
Profit == x(1)^2 + x(2)^2 + x(3)^2 + 8
];
Objective = Profit;
%% ------------------------------- %%
%% We do have many options
%% ------------------------------- %%
% Options = sdpsettings( 'verbose', 1, 'debug', 1 , 'solver', 'gurobi+', 'gurobi.NonConvex', '2', 'gurobi.MIPGap', '0.00000001');
Options = sdpsettings('solver', 'ipopt');
sol = optimize( Constraints, Objective , Options);
% Analyze error flags
if sol.problem == 0
% Extract and display value
display('========================================')
display('The min objective is ')
value(Objective)
display('========================================')
display('Thev variables are')
value(x)
display('========================================')
else
display('Hmm, something went wrong!');
sol.info yalmiperror(sol.problem)
end