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

6 次查看(过去 30 天)
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 个评论
Steven Lord
Steven Lord 2021-12-6
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 个)

类别

Help CenterFile Exchange 中查找有关 Function Creation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by