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

13 views (last 30 days)
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,

Accepted Answer

Sean de Wolski
Sean de Wolski on 11 Apr 2013
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 Comments
Steven Lord
Steven Lord on 6 Dec 2021
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);

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!