bugGNU Octave - Bugs: bug #47654, ode23/ode45 do not allow zero...

 
 

bug #47654: ode23/ode45 do not allow zero value for tolerance

Submitter:  Carlo de Falco <cdf>
Submitted:  Sat 09 Apr 2016 04:11:36 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  cdf
Originator Name:  Open/Closed:  Closed
Release:  dev Operating System:  Any
Fixed Release:  None Planned Release:  None

Discussion locked!

Jump to the original submission

Wed 23 Nov 2016 10:19:35 AM UTC, comment #6: 

Octave 4.2:


>> opt1 = odeset ('AbsTol', 0);
>> opt2 = odeset ('RelTol', 0);
>> opt3 = odeset ('AbsTol', 0, 'RelTol', 0);
>> ode23 (f, 1, [0 1], opt1)
error: ode23: TRANGE must contain at least 2 elements
error: called from
    ode23 at line 126 column 5
>> ode23 (f, [0 1], 1, opt1)
error: ode23: AbsTol must be positive
error: called from
    validateattributes at line 406 column 7
    odemergeopts at line 27 column 9
    ode23 at line 167 column 11
>> ode23 (f, [0 1], 1, opt2)
error: ode23: RelTol must be positive
error: called from
    validateattributes at line 406 column 7
    odemergeopts at line 27 column 9
    ode23 at line 167 column 11
>> ode23 (f, [0 1], 1, opt3)
error: ode23: AbsTol must be positive
error: called from
    validateattributes at line 406 column 7
    odemergeopts at line 27 column 9
    ode23 at line 167 column 11
>> ode45 (f, [0 1], 1, opt3)
error: ode45: AbsTol must be positive
error: called from
    validateattributes at line 406 column 7
    odemergeopts at line 27 column 9
    ode45 at line 161 column 11
>> ode45 (f, [0 1], 1, opt2)
error: ode45: RelTol must be positive
error: called from
    validateattributes at line 406 column 7
    odemergeopts at line 27 column 9
    ode45 at line 161 column 11
>> ode45 (f, [0 1], 1, opt1)
error: ode45: AbsTol must be positive
error: called from
    validateattributes at line 406 column 7
    odemergeopts at line 27 column 9
    ode45 at line 161 column 11
>>



Matlab 2016a


>> opt1 = odeset ('AbsTol', 0);
opt2 = odeset ('RelTol', 0);
opt3 = odeset ('AbsTol', 0, 'RelTol', 0);
>> ode23 (f, [0 1], 1, opt1)
Error using odearguments (line 131)
AbsTol must be positive.

Error in ode23 (line 114)
    odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);

>> ode23 (f, [0 1], 1, opt2)
Error using odearguments (line 123)
RelTol must be a positive scalar.

Error in ode23 (line 114)
    odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);

>> ode23 (f, [0 1], 1, opt3)
Error using odearguments (line 123)
RelTol must be a positive scalar.

Error in ode23 (line 114)
    odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);

>> ode45 (f, [0 1], 1, opt3)
Error using odearguments (line 123)
RelTol must be a positive scalar.

Error in ode45 (line 115)
    odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);

>> ode45 (f, [0 1], 1, opt2)
Error using odearguments (line 123)
RelTol must be a positive scalar.

Error in ode45 (line 115)
    odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);

>> ode45 (f, [0 1], 1, opt3)
Error using odearguments (line 123)
RelTol must be a positive scalar.

Error in ode45 (line 115)
    odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);

>>



The behaviour looks compatible to me, I think we can close this item.

Carlo de Falco <cdf>
Group Member
Wed 23 Nov 2016 04:28:07 AM UTC, comment #5: 

The current Octave code allows setting AbsTol or RelTol to 0.  However, ode23 will not allow a 0 for either tolerance.


error: ode23: RelTol must be positive
error: called from
    validateattributes at line 406 column 7
    odemergeopts at line 27 column 9
    ode23 at line 167 column 11


This is Matlab compatible.  Is that good enough and we can close this report?

Testing was done on the development branch with cset 86bb7c37a1b9.

Rik <rik5>
Group administrator
Sat 09 Apr 2016 03:32:14 PM UTC, comment #4: 

I have version R2016a, but I was wrong: Matlab is able to construct odeset with AbsTol or/and RelTol equal to zero.

What Matlab doesn't allow to do is to use inside ode23 and ode45 these options.
The output I posted was an error from the call to ode23 and ode45 and was not regarding odeset, that had correctly constructed the option struct.

The changeset I prepared fix the bug in odeset but allow ode23 and ode45 to receive AbsTol or RelTol equal to zero as input. This could be considered as an extension of Matlab code, or as an incompatibility. If this is the case, I will modify the code of these solvers in order to give the same output as Matlab (an error).


Francesco Faccio <francesco_faccio>
Sat 09 Apr 2016 02:30:53 PM UTC, comment #3: 

Hi Francesco, thanks for looking into this.
In Matlab 2005b I get:


>> opt=odeset('AbsTol', 0, 'RelTol', 1e-3)

opt =

              AbsTol: 0
                 BDF: []
              Events: []
         InitialStep: []
            Jacobian: []
           JConstant: []
            JPattern: []
                Mass: []
        MassSingular: []
            MaxOrder: []
             MaxStep: []
         NonNegative: []
         NormControl: []
           OutputFcn: []
           OutputSel: []
              Refine: []
              RelTol: 1.0000e-03
               Stats: []
          Vectorized: []
    MStateDependence: []
           MvPattern: []
        InitialSlope: []

>> opt=odeset('AbsTol', 0, 'RelTol', 1e-3)


what version of Matlab did you try on?


Carlo de Falco <cdf>
Group Member
Sat 09 Apr 2016 02:01:07 PM UTC, comment #2: 

Let me explain better the second point of the previous post: that warning appears when I set both AbsTol and RelTol to zero, because in function AbsRel_Norm there is an element by element division and the denominator depends on these two parameters. So for any index of the vectors AbsRel and AbsTol, there must be at most one element equal to zero.

I have checked the latest version of Matlab and if I set the options using opt=odeset('AbsTol', 0, 'RelTol', 1e-3) I get:


Error using odearguments (line 131)
AbsTol must be positive.


or, if I set RelTol to zero:


Error using odearguments (line 123)
RelTol must be a positive scalar.


In the latest version of Matlab it's not allowed to set one of these options to zero, so this may not be considered a bug anymore.

Francesco Faccio <francesco_faccio>
Sat 09 Apr 2016 12:25:54 PM UTC, comment #1: 

Dear Carlo,

I have modified the file ode_struct_value_check.m and now it is allowed to set RelTol=0 or AbsTol=0 (the changeset is in the file odestructvaluecheck.diff, I hope to have written it in the correct way).

While I was testing the code I discovered this


warning: division by zero
warning: called from
    AbsRel_Norm at line 41 column 12
    integrate_adaptive at line 133 column 9
    ode23 at line 332 column 16


so I have put an error message in the file AbsRel_Norm.m in order to check if almost one of the elements of the two vectors AbsTol and RelTol is set to zero. This changeset is in AbsRelNorm.diff

Should I write also some tests in ode23 and ode45?

Best regards,

Francesco Faccio



(file #36872, file #36873)

Francesco Faccio <francesco_faccio>
Sat 09 Apr 2016 04:11:36 AM UTC, original submission:  

In Matlab, odeset allows to set either 'AbsTol' or 'RelTol'
to 0, which is useful in order to disable one of the two
error checks.

In Octave this is not allowed:


>> odeset ('reltol', 0)
error: odeset: invalid value assigned to field 'RelTol'
error: called from
    ode_struct_value_check at line 227 column 13
    odeset at line 208 column 5


Carlo de Falco <cdf>
Group Member

 

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

Attached Files
file #36873:  AbsRelNorm.diff added by francesco_faccio (941B - text/x-patch)

 

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 francesco_faccio (Updated the item)
  • -email is unavailable- added by cdf (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.

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-11-23 cdf StatusNeed Info Fixed
        Open/ClosedOpen Closed
        Discussion LockNone Locked
    2016-11-23 rik5 StatusIn Progress Need Info
        Summaryodeset does not allow zero value for tolerance ode23/ode45 do not allow zero value for tolerance
    2016-04-09 francesco_faccio Attached File- Added odestructvaluecheck.diff, #36872
        Attached File- Added AbsRelNorm.diff, #36873

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code