0

I am trying to solve a problem (think excel "goal seek") where given a specific rate of return, matlab can solve for the variable "y" (which is used to multiply a matrix).

I've tried using fgoalattain (i don't understand it) and solve

here is the function which basically adds some arrays together to make a cashflow with y being a double. ppam_gen is a n*1 matrix. other_tot is a n*1 matrix. down_pmt is a double.

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))

does not work, the following error is given:

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))

and using symbolic toolbox doesn't work either.

syms y
solve(irr([-down_pmt ; y*ppam_gen + oth_tot]) == 0.15)

throws the error:

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
  • What does "does not work" mean? And what is the `irr` function? – horchler Aug 05 '13 at 19:18
  • I get this error Error using assignin Attempt to add "y" to a static workspace. See MATLAB Programming, Restrictions on Assigning to Variables for details. irr is internal rate of return Error in syms (line 66) assignin('caller',x,sym(x)); Error in ppa_model (line 130) syms y – user2616425 Aug 05 '13 at 19:44
  • The first error occurs at the line `ansirr = irr(cashflow);` and gives you a clear indication of what is happening inside of `irr`, which you didn't provide: the variable `cf` is either `NaN` or `+/-Inf`. You might try setting the lower and upper bound options for `fgoalattain`. The second error occurs at the line `syms y`. I don't know where you have this bit of code, but it seems like `y` may already be defined somehow. Run `clear y` or `reset(symengine)`. – horchler Aug 05 '13 at 20:01
  • Thank you for your help but it still isn't working. I've set the upper and lower bounds, i've cleared the symengine. I believe it has something to do with the fact that I am placing a variable within irr() but that's the whole objective really, i am trying to find an array (CF) that will give me an irr that we desire. – user2616425 Aug 05 '13 at 22:20
  • `solve` is also for symbolic calculations and I have no idea if you've converted everything to handle that. Not know what the `irr` function is, I can only suggest possibly looking looking at `fsolve` and of course debugging. – horchler Aug 05 '13 at 22:25

0 Answers0