Why getting different solutions by suppying same constraint to fmincon in two similar way (linear and nonlinear))?

조회 수: 1 (최근 30일)
I am using `fmincon` to solve a problem. The problem has some linear inequality constraints that are written in Matrix A and B. I can write these constraints in 2 way and I should get analogous results. But, weirdly I am getting different solutions. why is that?
1) In the first way, I can feed the constraint to 'fmincon' function as follows:
`[Xsqp, FUN ,FLAG ,Options] = fmincon(@(X)SQP(X,Dat),X,A,B,[],[],lb,ub,@(X)SQPnolcon(X,Dat,A,B),options);
% I comment the line 'C=A*X'-B;'
in the function 'SQPnolcon' and put C=[] instead, because A and B are defined already in fmincon function`
2) As the second way I can write it like this:
`[Xsqp, FUN ,FLAG ,Options] = fmincon(@(X)SQP(X,Dat),X,[],[],[],[],lb,ub,@(X)SQPnolcon(X,Dat,A,B),options);`
and also the constraint function as follows:
function [C,Ceq] = SQPnolcon(X,Dat,A,B)
C=A*X'-B;
Ceq = [];
end
Note: In the first, you're supplying A and B as both linear inequality constraints and as nonlinear inequality constraints, but in the second you're only supplying them as nonlinear inequality constraints. What option should I set for fmincon here to get same results?

채택된 답변

Brendan Hamm
Brendan Hamm 2015년 4월 17일
One possibility that I could see here is in the difference between how fmincon would treat the derivatives of linear and non-linear constraints. Since fmincon is a gradient based solver it will approximate the Hessian matrix. For a linear constraint we do not need to calculate the second order derivatives as they are all 0, so MATLAB will not bother. However, when you pass this as a non-linear constraint then these are approximated using finite-differences and are therefore unlikely to be 0 and will affect your results. Your best bet is to pass linear constraints as linear.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by