ons, 21 04 2010 kl. 19:26 +0200, skrev Ulrich Hoermann:

> I use the IRR code from the financial package, but it does not work.
> The bug seems to be related to the way, the irr.m calls the fsolve
> function. The error message is as follows:
>  
> error: error creating function handle "@npv (x, ...)"
> error: called from:
> error: C:\...\fsolve.m at line 138, column 9
> error: C:\...\irr.m at line 48, column 5
>  
> Thanks a lot for your help in advance.

Sorry about the late reply.

I am not familiar with this package, but it seems to me that the
following patch should solve the problem.

Can greater experts check this?

Søren

Index: irr.m
===================================================================
--- irr.m	(revision 7271)
+++ irr.m	(working copy)
@@ -27,24 +27,22 @@
 ## Author: KH <kurt.hor...@wu-wien.ac.at>
 ## Description: Internal rate of return of an investment
 
-function r = irr (p, i)
-
-  if (nargin == 1)
-    i = 0;
-  elseif (! (nargin == 2))
+function r = irr (p, i = 0)
+  ## Check input
+  if (nargin != 1 && nargin != 2)
     print_usage ();
   endif
 
   if (! (isvector (p)))
     error ("irr: p must be a vector");
-  else
-    p_string = cstrcat ("[", sprintf ("%.15f, ", p), "]");
   endif
 
   if (! isscalar (i))
     error ("irr: i must be a scalar");
   endif
 
-  r = fsolve (sprintf ("npv (x, %s) - %g", p_string, i), 0.01);
+  ## Solve system
+  f = @(x) npv (x, p) - i;
+  r = fsolve (f, 0.01);
 
 endfunction
------------------------------------------------------------------------------
_______________________________________________
Octave-dev mailing list
Octave-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/octave-dev

Reply via email to