ERROR: Undefined function 'minus' for input arguments of type 'function_handle'.

Hi,
I'm trying to run the following piece of code, I am confident in all my variables and f is basically a dummy function as my main concern is on my constraints.
f=@(X)X(1)+X(2); g=@(X)nonlcon(X,Incentive_FEE_FOF,FEES_INVESTORS,x_invB30(2:8),TBillRate,strategy_GROSS,FEES_EachFUND);
[FEE,fval]=fmincon(@(X)f,[2 5],[],[],[],[],[0 0],[100 100],g,options);
However, I get the following error:
  • Undefined function 'minus' for input arguments of type 'function_handle'.
Error in
/Applications/MATLAB_R2011b.app/toolbox/shared/optimlib/finitedifferences.p>finitedifferences
(line 156)
Error in nlconst (line 303)
[gf,gnc(:,nonlIneqs_idx),gnc(:,nonlEqs_idx),numEvals] = ...
Error in fmincon (line 794)
[X,FVAL,LAMBDA,EXITFLAG,OUTPUT,GRAD,HESSIAN]=...
*
My nonlcon is defined as follow:
function [c,ceq]=nonlcon(X,Incentive_FEE_FOF,FEES_INVESTORS,w,TBillRate,strategy_GROSS,FEES_EachFUND)
for i=1:193
Strategy_TOTALGROSS(i,1)=strategy_GROSS(i,:)*w;
if Strategy_TOTALGROSS(i,1)>=TBillRate
Incentive_FEE(i,1)=X(1)*(Strategy_TOTALGROSS(i,1)-TBillRate);
Strategy_TOTALNET(i,1)=Strategy_TOTALGROSS(i,1)-Incentive_FEE(i,1);
else
Strategy_TOTALNET(i,1)=Strategy_TOTALGROSS(i,1);
Incentive_FEE(i,1)=0;
end
end
F_Investors=Incentive_FEE +X(2);
F_Manager = F_Investors-FEES_EachFUND*w;
OLD_FEE_M=Incentive_FEE_FOF;
OLD_FEE_I=FEES_INVESTORS;
Investors=F_Investors-OLD_FEE_I;
Managers=OLD_FEE_M-F_Manager;
c=[Investors Managers];
ceq=[];
end
Could you please help?
Thanks in advance,

 採用された回答

Sean de Wolski
Sean de Wolski 2013 年 4 月 11 日
Please run the following:
dbstop if error
This will stop with the debugger on the offending line. You will then be able to inspect what is going on and figure out what is throwing the error.

3 件のコメント

Caroline
Caroline 2013 年 4 月 11 日
Thank you very much for your help! Problem was just in the declaration of f.
Have a great day and thanks again!
ELUMALAI E S
ELUMALAI E S 2021 年 12 月 6 日
What was the mistake you made in declaration? pls tell me
The problem was in the first input to fmincon.
f=@(X)X(1)+X(2);
% snip the definition of g
[FEE,fval]=fmincon(@(X)f,[2 5],[],[],[],[],[0 0],[100 100],g,options);
When fmincon calls its first input with a vector of values for X, that input returns the function handle f. It should instead return the value returned by evaluating f.
[FEE,fval]=fmincon(@(X)f(X),[2 5],[],[],[],[],[0 0],[100 100],g,options); % or
[FEE,fval]=fmincon(f, ... % since f is already a function handle
[2 5],[],[],[],[],[0 0],[100 100],g,options);

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeFunction Creation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by