nonlcon in fmincon not satisfying my constraints :( getting crazy.
古いコメントを表示
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.
回答 (1 件)
Titus Edelhofer
2012 年 5 月 16 日
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 件のコメント
DankoJones
2012 年 5 月 16 日
Richard Brown
2012 年 5 月 17 日
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
2012 年 6 月 25 日
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
2012 年 6 月 25 日
actually your constraint is linear, so you should insert it as such (it is likely to converge easier)
カテゴリ
ヘルプ センター および File Exchange で Choose a Solver についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!