0

我正在尝试解决一个问题(想想excel“目标搜索”),在给定特定回报率的情况下,matlab 可以解决变量“y”(用于乘以矩阵)。

我试过使用 fgoalattain (我不明白)并解决

这是一个函数,它基本上将一些数组加在一起以形成一个现金流,其中 y 是双倍的。ppam_gen 是一个*1 矩阵。other_tot 是一个*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
4

0 回答 0