## [Octave-cvsupdate] octave-forge/main/general rat.m,1.2,1.3 rats.m,1.1.1.1,1.2

 [Octave-cvsupdate] octave-forge/main/general rat.m,1.2,1.3 rats.m,1.1.1.1,1.2 From: Paul Kienzle - 2004-04-24 02:15:02 ```Update of /cvsroot/octave/octave-forge/main/general In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1398 Modified Files: rat.m rats.m Log Message: [for David Bateman] texinfo documentation, NDArray support Index: rats.m =================================================================== RCS file: /cvsroot/octave/octave-forge/main/general/rats.m,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- rats.m 10 Oct 2001 19:54:49 -0000 1.1.1.1 +++ rats.m 24 Apr 2004 02:14:53 -0000 1.2 @@ -14,21 +14,40 @@ ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -## S = rat(x,tol) -## Convert x into a rational approximation represented as a string. You -## can convert the string back into a matrix as follows: +## -*- texinfo -*- +## @deftypefn {Function File} {@var{s}} = rats (@var{x}, @var{tol}) +## +## Convert @var{x} into a rational approximation represented as a string. +## You can convert the string back into a matrix as follows: ## +## @example ## eval(["[",rats(hilb(4)),"];"]) +## @end example +## +## The optional second argument defines the tolerance to that the +## rational approximation will be calculated to. +## @end deftypefn +## @seealso{rat} -function T = rats(x) - if nargin != 1 - usage("S = rats(x)"); +function T = rats(x, tol) + if nargin != 1 && nargin != 2 + usage("S = rats(x, tol)"); endif - [n, d] = rat(x'); - [nr, nc] = size(x); + ## default norm + if (nargin < 2) + tol = 1e-6 * norm(x(:),1); + endif + + try + [n, d] = rat (permute (x, [2, 1, 3:ndims(x)]), tol); + catch + [n, d] = rat(x', tol); + end + sz = size (x); + nc = sz(2); + len = prod (sz); - len = nr*nc; S = sprintf("%d/%d ", [n(:), d(:)]'); if (len == 1) T = S; @@ -48,10 +67,10 @@ assign([1,index]) = assign([1,index]) + ceil(shift/2); assign(index) = assign(index) + floor(shift(1:len-1)/2); assign = cumsum(assign); - T = setstr(toascii(" ")*ones(1, nr*nc*cellsize+1)); + T = setstr(toascii(" ")*ones(1, len*cellsize+1)); T(assign+1) = S; - T(nc*cellsize+1:nc*cellsize:nr*nc*cellsize) = "\n"; - T(1)='\n'; + T(nc*cellsize+1:nc*cellsize:len*cellsize) = "\n"; + T(1)="\n"; endif -endfunction \ No newline at end of file +endfunction Index: rat.m =================================================================== RCS file: /cvsroot/octave/octave-forge/main/general/rat.m,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- rat.m 9 Aug 2002 20:47:47 -0000 1.2 +++ rat.m 24 Apr 2004 02:14:53 -0000 1.3 @@ -14,12 +14,19 @@ ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -## [n,d] = rat(x,tol) -## Find a rational approximation to x within tolerance using a continued -## fraction expansion. E.g, +## -*- texinfo -*- +## @deftypefn {Function File} {[@var{n}, @var{d}]} = rat (@var{x}, @var{tol}) ## +## Find a rational approximation to @var{x} within tolerance defined +## by @var{tol} using a continued fraction expansion. E.g, +## +## @example ## rat(pi) = 3 + 1/(7 + 1/16) = 355/113 ## rat(e) = 3 + 1/(-4 + 1/(2 + 1/(5 + 1/(-2 + 1/(-7))))) = 1457/536 +## @end example +## +## @end deftypefn +## @seealso{rats} function [n,d] = rat(x,tol) ```

 [Octave-cvsupdate] octave-forge/main/general rat.m,1.2,1.3 rats.m,1.1.1.1,1.2 From: Paul Kienzle - 2004-04-24 02:15:02 ```Update of /cvsroot/octave/octave-forge/main/general In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1398 Modified Files: rat.m rats.m Log Message: [for David Bateman] texinfo documentation, NDArray support Index: rats.m =================================================================== RCS file: /cvsroot/octave/octave-forge/main/general/rats.m,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- rats.m 10 Oct 2001 19:54:49 -0000 1.1.1.1 +++ rats.m 24 Apr 2004 02:14:53 -0000 1.2 @@ -14,21 +14,40 @@ ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -## S = rat(x,tol) -## Convert x into a rational approximation represented as a string. You -## can convert the string back into a matrix as follows: +## -*- texinfo -*- +## @deftypefn {Function File} {@var{s}} = rats (@var{x}, @var{tol}) +## +## Convert @var{x} into a rational approximation represented as a string. +## You can convert the string back into a matrix as follows: ## +## @example ## eval(["[",rats(hilb(4)),"];"]) +## @end example +## +## The optional second argument defines the tolerance to that the +## rational approximation will be calculated to. +## @end deftypefn +## @seealso{rat} -function T = rats(x) - if nargin != 1 - usage("S = rats(x)"); +function T = rats(x, tol) + if nargin != 1 && nargin != 2 + usage("S = rats(x, tol)"); endif - [n, d] = rat(x'); - [nr, nc] = size(x); + ## default norm + if (nargin < 2) + tol = 1e-6 * norm(x(:),1); + endif + + try + [n, d] = rat (permute (x, [2, 1, 3:ndims(x)]), tol); + catch + [n, d] = rat(x', tol); + end + sz = size (x); + nc = sz(2); + len = prod (sz); - len = nr*nc; S = sprintf("%d/%d ", [n(:), d(:)]'); if (len == 1) T = S; @@ -48,10 +67,10 @@ assign([1,index]) = assign([1,index]) + ceil(shift/2); assign(index) = assign(index) + floor(shift(1:len-1)/2); assign = cumsum(assign); - T = setstr(toascii(" ")*ones(1, nr*nc*cellsize+1)); + T = setstr(toascii(" ")*ones(1, len*cellsize+1)); T(assign+1) = S; - T(nc*cellsize+1:nc*cellsize:nr*nc*cellsize) = "\n"; - T(1)='\n'; + T(nc*cellsize+1:nc*cellsize:len*cellsize) = "\n"; + T(1)="\n"; endif -endfunction \ No newline at end of file +endfunction Index: rat.m =================================================================== RCS file: /cvsroot/octave/octave-forge/main/general/rat.m,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- rat.m 9 Aug 2002 20:47:47 -0000 1.2 +++ rat.m 24 Apr 2004 02:14:53 -0000 1.3 @@ -14,12 +14,19 @@ ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -## [n,d] = rat(x,tol) -## Find a rational approximation to x within tolerance using a continued -## fraction expansion. E.g, +## -*- texinfo -*- +## @deftypefn {Function File} {[@var{n}, @var{d}]} = rat (@var{x}, @var{tol}) ## +## Find a rational approximation to @var{x} within tolerance defined +## by @var{tol} using a continued fraction expansion. E.g, +## +## @example ## rat(pi) = 3 + 1/(7 + 1/16) = 355/113 ## rat(e) = 3 + 1/(-4 + 1/(2 + 1/(5 + 1/(-2 + 1/(-7))))) = 1457/536 +## @end example +## +## @end deftypefn +## @seealso{rats} function [n,d] = rat(x,tol) ```