home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / SPECFUN.DI$ / RATS.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  1.1 KB  |  39 lines

  1. function S = rats(X,lens)
  2. %RATS    Rational output.
  3. %    RATS(X,LENS) uses RAT to display rational approximations to
  4. %    the elements of X.  The string length for each element is LENS.
  5. %    The default is LENS = 13, which allows 6 elements in 78 spaces.
  6. %    Asterisks are used for elements which can't be printed in the
  7. %    alloted space, but which are not negligible compared to the other
  8. %    elements in X.
  9. %
  10. %    The same algorithm, with the default LENS, is used internally
  11. %    by MATLAB for FORMAT RAT.
  12. %
  13. %    See also FORMAT, RAT.
  14.  
  15. %    Cleve Moler, 10-28-90.
  16. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  17.  
  18. if nargin < 2, lens = 13; end
  19. lhalf = fix(lens/2);
  20. tol = 10^(-lhalf) * norm(X(:),1);
  21. [N,D] = rat(X,tol);
  22. [m,n] = size(X);
  23. S = [];
  24. nform = ['%' num2str(lhalf) '.0f'];
  25. dform = ['%-' num2str(lhalf) '.0f'];
  26. for i = 1:m
  27.     s = [];
  28.     for j = 1:n
  29.         sj = sprintf(nform,N(i,j));
  30.         if D(i,j) ~= 1
  31.             sj = [sj '/' sprintf(dform,D(i,j))];
  32.         else
  33.             sj = [' ' sj '      '];
  34.         end
  35.         s = [s sj];
  36.     end
  37.     S(i,:) = s;
  38. end
  39.