ERROR: Undefined function 'minus' for input arguments of type 'function_handle'.
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Caroline
am 11 Apr. 2013
Kommentiert: Steven Lord
am 6 Dez. 2021
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,
0 Kommentare
Akzeptierte Antwort
Sean de Wolski
am 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 Kommentare
Steven Lord
am 6 Dez. 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);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Function Creation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!