我正在尝试解决一个问题(想想excel“目标搜索”),在给定特定回报率的情况下,matlab可以求解变量“y”(用于乘以矩阵)。
我尝试过使用fgoalattain(我不明白)并解决
这里的功能基本上是将一些数组加在一起,使y为双倍的现金流。 ppam_gen是一个n * 1矩阵。 other_tot是一个n * 1矩阵。 down_pmt是双倍的。
function ansirr = cirr(y)
cf_gen_oth = y*ppam_gen + oth_tot
dp = [-down_pmt]
cashflow = [dp;cf_gen_oth]
ansirr = irr(cashflow)
%ansirr = irr([dp; y*ppam_gen + oth_tot])
end
x = fgoalattain(@cirr,0.001,.15,abs(.15))
不起作用,给出以下错误:
Error using roots (line 28)
Input to ROOTS must not contain NaN or Inf.
Error in irr (line 134)
coeff = roots(fliplr(cf(:,loop)')); % Find roots of polynomial
Error in ppa_model/cirr (line 139)
ansirr = irr(cashflow)
Error in goalcon (line 26)
f = feval(funfcn{3},x,varargin{:});
Error in
fgoalattain>@(y,varargin)feval(cfun{3},y,neqgoals,funfcn,confcn,WEIGHT,GOAL,x,errCheck,varargin{:})
(line 473)
cfun{3} = @(y,varargin)
feval(cfun{3},y,neqgoals,funfcn,confcn,WEIGHT,GOAL,x,errCheck,varargin{:});
Error in nlconst (line 746)
[nctmp,nceqtmp] = feval(confcn{3},x,varargin{:});
Error in fgoalattain (line 519)
[xnew,ATTAINFACTOR,LAMBDA,EXITFLAG,OUTPUT]=...
Error in ppa_model (line 152)
r = fgoalattain(@cirr,0.001,.15,abs(.15))
并且使用符号工具箱也不起作用。
syms y
solve(irr([-down_pmt ; y*ppam_gen + oth_tot]) == 0.15)
抛出错误:
Error using assignin
Attempt to add "y" to a static workspace.
See MATLAB Programming, Restrictions on Assigning to Variables for details.
Error in syms (line 66)
assignin('caller',x,sym(x));
Error in ppa_model (line 152)
syms y