octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #43871] fzero produces innacurate results (whi


From: Fedja Beader
Subject: [Octave-bug-tracker] [bug #43871] fzero produces innacurate results (while MATLAB produces analytically correct one +-eps)
Date: Mon, 22 Dec 2014 18:14:45 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0

URL:
  <http://savannah.gnu.org/bugs/?43871>

                 Summary: fzero produces innacurate results (while MATLAB
produces analytically correct one +-eps)
                 Project: GNU Octave
            Submitted by: specing
            Submitted on: Mon 22 Dec 2014 06:14:44 PM GMT
                Category: Octave Function
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Inaccurate Result
                  Status: None
             Assigned to: None
         Originator Name: 
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 3.8.2
        Operating System: Any

    _______________________________________________________

Details:

function v = legendre(n, x)

        if (n == 0)
                v = 1;
        elseif (n == 1)
                v = x;
        else
                v = (2 .* n - 1) .* x .* legendre(n - 1, x) - (n - 1) .* 
legendre(n - 2,
x);
                v = v ./ n;
        end
end



octave:12> f = @(x)egendre(3,x)                                               
     
f =

@(x) legendre (3, x)

octave:15> fzero(f, 0.9)
ans =  0.774596655245828

% exact result, calculated analytically and printed by Matlab+-eps
octave:19> sqrt(3/5)
ans =  0.774596669241483
                ^
% seems to only be accurate to half the digits?



% same with legendre(2,x):

octave:22> f = @(x) legendre(2,x)                                             
         
f =

@(x) legendre (2, x)

octave:23> sqrt(3)/3
ans =  0.577350269189626
octave:24> fzero(f, 0.5)
ans =  0.577350255189640





    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?43871>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]