ERROR: Undefined function 'minus' for input arguments of type 'function_handle'.
조회 수: 7 (최근 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,
댓글 수: 0
채택된 답변
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
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 Center 및 File Exchange에서 Function Creation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!