maximizing a function with a nonlinear constraint using fmincon

2 ビュー (過去 30 日間)
ektor
ektor 2018 年 1 月 21 日
編集済み: Matt J 2018 年 1 月 21 日
Dear all,
I have a function 'fun' which I want to maximize with respect to four unknowns: x(1) x(2) x(3) and x(4)
under the constraint
exp(x(2))+exp(x(3))<0.99
So, I set up something like that
function [c,ceq] = mycon(x)
c= exp(x(2))+exp(x(3))-0.99;
ceq=[];
end
x0=[a ;b c; d] % the initial value
options=optimset( 'display','off'); % mainly use this
[xx,fval,exitflag,output,lambda,grad,HH]=fmincon('fun',x0,...
[],[],[],[],[],[],@mycon, options);
But I get this warning
Error using mycon
Too many input arguments.
Error in fmincon (line 622)
[ctmp,ceqtmp] = feval(confcn{3},X,varargin{:});
Error in dokimi_3 (line 96)
[xx,fval,exitflag,output,lambda,grad,HH]=fmincon('fun',x0,...
Caused by:
Failure in initial nonlinear constraint function evaluation. FMINCON cannot continue.
Any ideas what is wrong?
Thank you
  3 件のコメント
Walter Roberson
Walter Roberson 2018 年 1 月 21 日
Is it possible that in your actual code that you passed something to fmincon after the options argument?
ektor
ektor 2018 年 1 月 21 日
編集済み: ektor 2018 年 1 月 21 日
Thanks Walter
Yes, actually my complete set up is the following
[xx,fval,exitflag,output,lambda,grad,HH]=fmincon('fun',x0,...
[],[],[],[],[],[],@mycon , options,y,mu, psi,sig20, Vgam,gam0, lam0,Vlam );
where ,y,mu, psi,sig20, Vgam,gam0, are known values that are inserted in the "fun" file
And I get the above error.

サインインしてコメントする。

採用された回答

Matt J
Matt J 2018 年 1 月 21 日
編集済み: Matt J 2018 年 1 月 21 日
Rewrite mycon to have this form,
function [c,ceq] = mycon(x, y,mu, psi,sig20, Vgam,gam0, lam0,Vlam )
c= exp(x(2))+exp(x(3))-0.99;
ceq=[];
end
Even if the extra known variables aren't actually used in the computations of the constraints, they have to be there if you use additional arguments to fmincon to pass them in.
Incidentally, passing extra known parameters this way is antiquated. You should use anonymous or nested functions as described here. If you use these alternatives, you will not have to have to pass variables to functions that don't need them.

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by