I am using fmincon for a nonlinear program where one of the constraints restricts the decision variable x to periodic intervals as defined:
where , T is the periodicity, and is the length of the interval.
I thought an elegant way to write this constraint was to use modulo in the inequality constraint:
c = mod(x,T)-D*T;
But the solver either exceeds the max iterations or converges to an infeasible point – unless I choose the right starting point within a very narrow window only possible by inspection.
However, if I explicitly write out an interval as two inequality constraints:
c(1) = -x+T;c(2) = x-(T+D*T);
Then it converges to a feasible local min. Obviously, this is a specific interval where I specify a particular k so I'd like to generalize the constraint for all
For a real basic example, if I choose , I have these constraints resulting in differing fmincon behavior:
c = mod(x,40)-20;% versus
c(1) = -x+40;c(2) = x-60;
My main question is why the solver behaves differently when the above constraints are mathematically equivalent? My only guess is that the interior point algo is sensitive to initial points. But for some reason, even if I start with , the former constraint results in infeasibility whereas the latter solves the problem.
Is there a way around this or perhaps reformulate the constraints as to not require an expensive loop?
Best Answer