How should I use Fmincon function when I just have linear constraints but Nonlinear objective function?
1 回表示 (過去 30 日間)
古いコメントを表示
Hi my objective function is nonlinear, and my only constraints are:
x(1)<0.00125
x(1)>0
x(2)>0
And I wanna solve it with interior point optimzation method I get error for this code :
x0=[1.1;3]; % Starting guess
B = [1.25;20.0];
A = [1,0;0,1];
lb=[0.5;0.4];
up=[1.25;20.0];
Aeq=[];
beq=[];
options=optimset('outputfcn',@outfun,'Largescale','off','Algorithm','interior-point','Display','iter','Tolx',1e-15,'Tolfun',1e-16,'MaxFunEvals',60000,'MaxIter',1000);
[x,fval,exitflag,output]=fmincon(@optim,x0,A,B,Aeq,beq,lb,ub,options);
it said I need a nonlcons in my Fmincon function So I add this function
function [c,ceq]=const(x)
c(1)=x(1)-0.00125;
c(2)=-x(1);
c(3)=-x(2);
ceq=[];
end
and add these to my code:
nonlcon=@const
[x,fval,exitflag,output]=fmincon(@optim,x0,A,B,Aeq,beq,lb,ub,'nonlcon',options);
But I still get error for this nonlcon :(
0 件のコメント
採用された回答
Alan Weiss
2017 年 11 月 9 日
Your problem is that you are using options in the place where fmincon expects to see nonlinear constraints. In other words, your call should be
[x,fval,exitflag,output]=fmincon(@optim,x0,A,B,Aeq,beq,lb,ub,[],options);
But wait, there's more. You should NOT use A and B to set bounds. And you have lb and ub that do not make sense to me, because you say that your only constraints are x(i) > 0 and x(1) < 0.00125. So get rid of A, B, nonlcon, and set
lb = [0,0];
ub = [0.00125,Inf];
[x,fval,exitflag,output]=fmincon(@optim,x0,[],[],[],[],lb,ub,[],options);
Alan Weiss
MATLAB mathematical toolbox documentation
7 件のコメント
Alan Weiss
2017 年 11 月 10 日
I understand the result of this experiment is that your objective function throws an error for some points, I suspect for points that are not integer-valued. I suggest that you use the debugger to find out why your objective function throws an error for some points. fmincon works for continuous problems, meaning the objective function must be able to be evaluated for real points that are not restricted to integer values.
Alan Weiss
MATLAB mathematical toolbox documentation
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Nonlinear Optimization についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!