nonlcon in fmincon not satisfying my constraints :( getting crazy.
Mostrar comentarios más antiguos
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.
Respuestas (1)
Titus Edelhofer
el 16 de Mayo de 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 comentarios
DankoJones
el 16 de Mayo de 2012
Richard Brown
el 17 de Mayo de 2012
that's still not right - the body of your function should be
function [c, ceq] = mycon(x0)
ceq = [];
c = x0(3) - 0.1*x0(2);
end
and that's it
Steve Grikschat
el 25 de Jun. de 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
el 25 de Jun. de 2012
actually your constraint is linear, so you should insert it as such (it is likely to converge easier)
Categorías
Más información sobre Solver Outputs and Iterative Display en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!