bugGNU Octave - Bugs: bug #43717, rats LEN Matlab incompatibility


bug #43717: rats LEN Matlab incompatibility

Submitted by:  Andreas Weber <andy1978>
Submitted on:  Thu 27 Nov 2014 08:27:40 PM UTC  
Category:  Octave Function Severity:  2 - Minor
Priority:  3 - Low Item Group:  WTF, Matlab?!?
Status:  Need Info Assigned to:  None
Originator Name:  Open/Closed:  Open
Release:  dev Operating System:  Any

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Thu 06 Jun 2019 03:49:24 PM UTC, comment #2: 

The documentation for Matlab now makes this quite clear.  According to them, the construction of a rational approximation with rats() is done via the function rat and a tolerance.

[N,D] = rat(X,tol)
where tol is min(10^(-(strlen-1)/2)*norm(X(isfinite(X)),1),.1)

I agree with the original reporter that I wouldn't bother to fix this as Octave's solution seems better.

One thing I do notice is that Matlab seems to have changed the default length to 13 from 9.  Should Octave make that change?

Rik <rik5>
Project Administrator
Tue 01 May 2018 08:35:11 PM UTC, comment #1: 

Still present. It seems to me that Matlab is trying to ensure that at least one space is included at the start and end of the string, so that the strings can always be safely concatenated end-to-end.

Mike Miller <mtmiller>
Project Administrator
Thu 27 Nov 2014 08:27:40 PM UTC, original submission:  

Octave tries to find an approximation which fits into LEN (second arg of rats) but Matlab seems to do some fancy stuff to calculate a tolerance from the input vector X and LEN and then call rat with this tolerance. The strings returned from Matlab are often less shorter than LEN even if a better approximation would be possible.

For example octave returns 22/7 for rats(pi, 4) whereas Matlab returns "  *", see http://octave.1599824.n4.nabble.com/Matlab-output-from-quot-rats-quot-wanted-tt4667406.html and the Matlab documentation under More About - Algorithms.

Personally I think Octave's behaviour is much better here but I want to document this here.

If someone want to investigate this further: Try a changeset after c490eac28bbb which fixed an overflow in rats (#43369).

Andreas Weber <andy1978>
Project Member


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

Attach Files:

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 (Updated the item)
  • -email is unavailable- added by andy1978 (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.




    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-06-06 mtmiller Carbon-CopyRemoved 80942 => -
    2019-06-06 rik5 StatusNone => Need Info
    2018-05-01 mtmiller Severity3 - Normal => 2 - Minor
        Release3.8.2 => dev
    2015-01-01 andy1978 Item GroupMatlab Compatibility => WTF, Matlab?!?
    2014-12-31 rik5 Priority5 - Normal => 3 - Low

    Back to the top

    Powered by Savane 3.5