Masan
Masan

Reputation: 345

Why getting different solutions by feeding constraint to fmincon in two similar way?

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

Upvotes: 2

Views: 253

Answers (1)

Sam Roberts
Sam Roberts

Reputation: 24127

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.

I get why you might expect that would be equivalent, since they're the same constraints anyway. But the linear equality constraints are applied in a different context than the nonlinear equality constraints, and that leads the optimization algorithm to find a different solution.

I'm afraid I'm not able to explain exactly how the two different types of constraints are applied, and at what points in the algorithm - and in any case, this would vary depending on which algorithm you're asking fmincon to use (active-set, trust-region and so on). For that level of detail, you might need to ask MathWorks. But the basic answer is that you're getting different results because you're asking the algorithm to do two different things.

Upvotes: 2

Related Questions