On 18 November 2011 13:32, Júlio Maranhão <ju...@maranhao.us> wrote:
> 2011/11/17 Juan Pablo Carbajal <carba...@ifi.uzh.ch>:
>> Octave 3.4.3, financial 0.3.2
>> octave:2> rate(30, 510.19, 10000)
>> error: @pv (x, 30, 510.19, 0, "e") - 10000: no function and no method found
>> error: called from:
>> error:   /usr/local/share/octave/3.4.3-rc0/m/optimization/fsolve.m at
>> line 149, column 9
>> error:   /home/juanpi/octave/financial-0.3.2/rate.m at line 69, column 5
>>
>> You may want to move forward in the version of Octave. If you are in
>> 32bits you can try out this binaries, they were successfully tested
>> many times by now.
>> http://ubuntuone.com/6l35Gf3j8alWL7fGeYW388
>>
>
> Juan, what do you mean by "successfully tested many times by now"? You
> show an example of failure from the last Octave/financial pair. Why
> should I change the version if it seams to not solve the issue?

I think he meant that the deb, while not part of the official ubuntu
repositories, has been tested many times. While, yes maybe it won't
fix this problem, the newer version has more functions and bug fixes
which is good.

> By the way, irr()

This problem in irr() has been fixed in the development version.

> [...] and rate() do errors because they call fsolve() with
> a string as an argument. Example:
>
> octave:3> fsolve("pv (x, 30, 510.19, 0, \"e\") - 10000",0)
> error: error creating function handle "@pv (x, 30, 510.19, 0, "e") - 10000"
> error: called from:
> error:   /usr/share/octave/3.2.4/m/optimization/fsolve.m at line 138, column 9
>
> But with another syntax:
>
> octave:4> fsolve(@(x)pv(x, 30, 510.19) - 10000 , 0)
> ans =  0.019085  # wrong. 0.03 is correct.
>
> octave:6> fsolve(@(x)x-1 , 0)
> ans =  1.0000  # right
>
> octave:7> fsolve(@(x)-x^2+4, 0)
> warning: division by zero
> warning: division by zero
> .
> .
> .
> ans = 0  # wrong, but initial value is not good.
>
> octave:8> fsolve(@(x)-x^2+4, 0.1)
> ans =  2.0000  # now right, with a good initial value.
>
> I am new to octave and I don't know if the way to call fsolve() is an issue.

I believe I may have fixed your issue. The problem is indeed with the
way fsolve is being called. Could you please test the attached
function file?

The way to fix this is something like:
  f = @(x) pv (x, n, p, l, m) - v;
  r = fsolve (f, 0);

Carnë
## Copyright (C) 1995, 1996, 1997, 1998, 2000, 2002, 2004, 2005, 2006,
##               2007 Kurt Hornik <kurt.hor...@wu-wien.ac.at>
##
## This program is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or (at
## your option) any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; see the file COPYING.  If not, see
## <http://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn {Function File} {@var{r} =} rate (@var{n}, @var{p}, @var{v}, @var{l}, @var{method})
## Return the rate of return @var{r} on an investment of present value @var{v}
## which pays @var{p} in @var{n} consecutive periods.
##
## The optional argument @var{l} may be used to specify an additional
## lump-sum payment made at the end of @var{n} periods.
##
## The optional string argument @var{method} may be used to specify
## whether payments are made at the end (@code{"e"}, default) or at the
## beginning (@code{"b"}) of each period.
## @seealso{pv, pmt, nper, npv}
## @end deftypefn

function r = rate (n, p, v, l, m)

  if (nargin < 3 || nargin > 5)
    print_usage ();
  endif

  if (! (isscalar (n) && n > 0))
    error ("rate: n must be a positive scalar");
  elseif (! isscalar (p))
    error ("rate: p must be a scalar");
  elseif (! isscalar (v))
    error ("rate: p must be a scalar");
  endif

  if (nargin == 5)
    if (! ischar (m))
      error ("rate: `method' must be a string");
    endif
  elseif (nargin == 4)
    if (ischar (l))
      m = l;
      l = 0;
    else
      m = "e";
    endif
  else
    l = 0;
    m = "e";
  endif

  if (! isscalar (l))
    error ("rate: l must be a scalar");
  endif

  f = @(x) pv (x, n, p, l, m) - v;
  r = fsolve (f, 0);

endfunction
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure 
contains a definitive record of customers, application performance, 
security threats, fraudulent activity, and more. Splunk takes this 
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Octave-dev mailing list
Octave-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/octave-dev

Reply via email to