octave-maintainers
[Top][All Lists]
Advanced

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

Re: rat and rats ported from octave-forge


From: John W. Eaton
Subject: Re: rat and rats ported from octave-forge
Date: Mon, 23 Jul 2007 16:37:42 -0400

On 23-Jul-2007, David Bateman wrote:

| David Bateman wrote:
| > John W. Eaton wrote:
| >   
| >> On 20-Jul-2007, David Bateman wrote:
| >>
| >> | I hesitated in the past to port the rat and rats functions from
| >> | octave-forge as we don't have the "format rat" command available. Also
| >> | the octave-forge rats command used a tolerance rather than a maximum
| >> | string length. Attached is a patch that ports the rat function from
| >> | octave-forge, implements the "format rat" command and reimplements rats
| >> | in terms of the "format rat" display code. Note that the results are
| >> | slightly different that matlab in a couple of cases..
| >> | 
| >> | 1) Something like 1.233 will be represented as 1233/1000 in matlab,
| >> | whereas in octave it will be represented as 127/103
| >> | 2) Matlab seems to stop expanding the representation earlier than it
| >> | needs to. For example in matlab 1.0014 is represented as 700/699, where
| >> | as in Octave 7003/6993 which equally well fits in the maximum string
| >> | length.
| >>
| >> My guess is that someone will eventually complain that the results are
| >> not precisely the same, but I'm not sure that matters at this point.
| >>   
| >>     
| > For case 1) I think matlab is probably right to do what it does, I just
| > have figured out a good way to duplicate it yet.. For point 2) matlab is
| > not doing what it says it is doing in its documentation. It says it
| > gives a string representation of the rational approximation upto a
| > certain string length, where as it gives the first it finds of the
| > maximum string length... I'd stick with the behavior I proposed..
| >   
| Ok, I figured out what was wrong with case 1)... Basically the
| fractional representation can have a negative numerator and denominator
| and the signs are fixed at the end... For the representation of 1.233
| this was the case and as "-1233/-1000" is longer than 9 characters it
| was dropped as a valid representation. To get this right I had to check
| the sign of the numerator and the denominator and check for string up to
| two characters longer than actually desired.. The attached version of
| the patch fixes this issue (and a small convergence test issue)..
| Basically I think this version pretty much duplicates matlabs behavior
| expect for point two above and that "rats" doesn't inlcude the leading
| four whitespaces that matlab appends in the string length, as Octave
| doesn't add them...

Please check in these changes.

Thanks,

jwe


reply via email to

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