nonlcon in fmincon not satisfying my constraints :( getting crazy.

15 views (last 30 days)
I'm currently trying to satisfy non linear constraints through adding a nonlcon in my fmincon function, however when optimizing, it is not satisfying my constraints :( at all.
% vector of initial weights
x0=zeros(8,1)
this is my nonlcon function. The idea behind this constraint is that at any point, the weights in asset 3 can only be 10% of the weight in asset 2.
----------weights x0----------
function [c, ceq] = mycon(x0)
ceq=[];
c=[];
% (x0(3)) - (0.1*x0(2)) < 0 ;
% c(1) = (x0(3)) - (0.1*x0(2)) < 0 ;
% c < 0;
c(1) = x0(3)<(0.1*x0(2)) ;
This is my fmincon:
[weights] = fmincon(@(x0) (a typical function),x0,[],[],Aeq,beq,zeros(size(Data,2),1),C,'mycon',optimopt);
Where i've tried
'mycon'
and
@(x0)mycon(x0)
for the nonlcon place in fmincon. I'm running this through a for loop where i've created a return constraint in my Aeq. What i'm looking for while optimizing through fmincon is that it satisfies the constraints in my nonlcon at every 'required return' step. However, at any(!) point, it does not satisfy my nonlcon, but it does run perfectly smooth. With no error messages.

Answers (1)

Titus Edelhofer
Titus Edelhofer on 16 May 2012
Hi,
fmincon will try to satisfy the relation c<0. To this end you need to compute c, but you give the relation. So: you need to write
c = x0(3)-0.1*x0(2);
Now: when the optimizer uses the computed c and satisfies "c<0", your relation x0(3)<0.1*x0(2) will be satisfied ....
Titus
  4 Comments
Steve Grikschat
Steve Grikschat on 25 Jun 2012
The use of the logical operation "<" makes this nonlinear constraint non-smooth: either 0 or 1. This can be unmanageable for fmincon, which works best with smooth, continuous functions. Try Richard's coding.
Sargondjani
Sargondjani on 25 Jun 2012
actually your constraint is linear, so you should insert it as such (it is likely to converge easier)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!