bugGNU Octave - Bugs: bug #53583, auto-bracketing algorithm for...

 
 

bug #53583: auto-bracketing algorithm for fzero could be improved

Submitter:  None
Submitted:  Sat 07 Apr 2018 08:13:40 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  zertyuiop Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 4.2.2
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 09 Apr 2018 12:33:46 AM UTC, comment #4: 

It wasn't that hard to tweak the zero-bracketing algorithm.  I did that here http://hg.savannah.gnu.org/hgweb/octave/rev/57f150c4fe6d.

Octave is now Matlab-compatible.


octave:2> fzero(@(x) besselj(0, x), pi*11-pi/4)
ans =  33.776
octave:3> fzero(@(x) besselj(0, x), pi*10-pi/4)
ans =  30.635


It is still recommended procedure to call fzero with your own bracketing range.

Marking as fixed and closing report.


Rik <rik5>
Group administrator
Sun 08 Apr 2018 03:42:10 PM UTC, comment #3: 

Octave also accepts a scalar.  See the last part of the documentation from comment #1:


 If X0 is a single scalar then several nearby and distant values are
 probed in an attempt to obtain a valid bracketing.  If this is not
 successful, the function fails.


The issue is that if you don't give fzero a valid bracketing around the zero you want it may probe and find a nearby zero instead.  Taking not bessel, but sin(x) which has zeros at 0, pi, 2*pi, 3*pi, etc.  What value should be returned for


fzero (@sin, pi/2)


In this case, the algorithm chooses 0, but it could just as well have chosen the one at pi, or even one further away because the instructions weren't explicit enough.

I suppose the auto-bracketing mechanism could be re-written.  It's only a few lines, but because the characteristics of the function are not known we don't rely on derivatives.

Rik <rik5>
Group administrator
Sun 08 Apr 2018 08:20:09 AM UTC, comment #2: 

Matlab (now) accepts a scalar as x0. So, it is a compatibility bug.

Marco Caliari <caliari>
Group Member
Sat 07 Apr 2018 08:48:02 PM UTC, comment #1: 

The initial guess should be a 2-element vector which brackets the zero you are trying to find.  Try 'help fzero'


 X0 should be a two-element vector specifying two points which
 bracket a zero.  In other words, there must be a change in sign of
 the function between X0(1) and X0(2).  More mathematically, the
 following must hold

      sign (FUN(X0(1))) * sign (FUN(X0(2))) <= 0

 If X0 is a single scalar then several nearby and distant values are
 probed in an attempt to obtain a valid bracketing.  If this is not
 successful, the function fails.


If you give it a single scalar then it has to try and find a bracketing range around the point given and it may discover a range which includes another zero.

If you bracket the zero you want to find there is no issue


fzero(@(x) besselj(0, x), [33 35])
ans =  33.776



Rik <rik5>
Group administrator
Sat 07 Apr 2018 08:13:40 PM UTC, original submission:  

Octave gives:


>> fzero(@(x) besselj(0, x), pi*11-pi/4)
ans =  30.635
>> fzero(@(x) besselj(0, x), pi*10-pi/4)
ans =  30.635


when MATLAB:


>> fzero(@(x) besselj(0, x), pi*11-pi/4)

ans =

   33.7758

>> fzero(@(x) besselj(0, x), pi*10-pi/4)

ans =

   30.6346


Scilab gives:


--> deff('[z]=bess(x)','z=besselj(0,x)')

--> fsolve(%pi*11-%pi/4, bess)
 ans  =

   33.77582


--> fsolve(%pi*10-%pi/4, bess)
 ans  =

   30.634606



Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by caliari (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-04-09 rik5 StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2018-04-08 rik5 Summaryfzero should accept x0 as a scalar auto-bracketing algorithm for fzero could be improved
    2018-04-08 caliari Item GroupInaccurate Result Matlab Compatibility
        StatusWorks For Me Confirmed
        Summaryfzero inaccurate result for Bessel function fzero should accept x0 as a scalar
    2018-04-07 rik5 StatusNone Works For Me

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code