bugGNU Octave - Bugs: bug #36923, Bug in fminbnd?

 
 

bug #36923: Bug in fminbnd?

Submitter:  Nir Krakauer <nir_krakauer>
Submitted:  Mon 23 Jul 2012 04:19:02 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Nir Krakauer Open/Closed:  * Closed
Release:  * 3.6.1 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 16 Jan 2014 01:24:00 AM UTC, comment #2: 

I checked in the simpler change of '<=' going to '<'.  I also added a %!test to check the new behavior.  See http://hg.savannah.gnu.org/hgweb/octave/rev/61dab64aa5a6.

Rik <rik5>
Group administrator
Wed 08 Jan 2014 01:02:18 AM UTC, comment #1: 

The same effect can be had by changing line 192 of fminbnd.m from


if (fu <= fval)


to


if (fu < fval)


There is the following comment in the original code:


## The following if-statement was originally executed even if fu == fval.


By dropping the '=' the code goes back to the "original", whatever that means.  I'm tempted to use this fix since it means 2 fewer function evaluations, however I don't pretend to have studied the algorithm and know if this is okay.


Rik <rik5>
Group administrator
Mon 23 Jul 2012 04:19:02 PM UTC, original submission:  

For functions that are flat after the first 38% (2-phi) of the interval, fminbnd doesn't return the minimum even if it's reached at one endpoint, e.g.

[x, fval, info] = fminbnd(@(x) (x > 0.3), 0, 1)

returns

x =  1.00000
fval =  1
info =  1


This can apparently be fixed at the cost of evaluating the function at the interval endpoints. I inserted after line 96 ('fv = fw = fval = fun (x);') in fminbnd.m


  ## set x equal to one of the endpoints if the function value there is lower than at v
  fa = fun (a);
  if fa < fv
          x = a;
          w = v;
          fw = fv;
          fval = fa;
  end
  fb = fun (b);
  if fb < fv
          x = b;
          w = v;
          fw = fv;
          fval = fb;
  end


After this modification,

[x, fval, info] = fminbnd(@(x) (x > 0.3), 0, 1)

returns, correctly,

x =  5.7206e-09
fval = 0
info =  1

Nir Krakauer <nir_krakauer>

 

(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 rik5 (Posted a comment)
  • -email is unavailable- added by mtmiller (Updated the item)
  • -email is unavailable- added by nir_krakauer (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 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-01-16 rik5 StatusNeed Info Fixed
        Open/ClosedOpen Closed
    2014-01-08 rik5 StatusPatch Submitted Need Info
    2013-10-28 mtmiller CategoryNone Octave Function
        StatusNone Patch Submitted

    Back to the top

    Powered by Savane 3.13-bb6a.
    Corresponding source code