home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fb.zip / octave / SCRIPTS.ZIP / scripts / general / logspace.m < prev    next >
Encoding:
Text File  |  1999-11-21  |  2.2 KB  |  96 lines

  1. ## Copyright (C) 1996, 1997 John W. Eaton
  2. ##
  3. ## This file is part of Octave.
  4. ##
  5. ## Octave is free software; you can redistribute it and/or modify it
  6. ## under the terms of the GNU General Public License as published by
  7. ## the Free Software Foundation; either version 2, or (at your option)
  8. ## any later version.
  9. ##
  10. ## Octave is distributed in the hope that it will be useful, but
  11. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. ## General Public License for more details.
  14. ##
  15. ## You should have received a copy of the GNU General Public License
  16. ## along with Octave; see the file COPYING.  If not, write to the Free
  17. ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  18. ## 02111-1307, USA.
  19.  
  20. ## -*- texinfo -*-
  21. ## @deftypefn {Function File} {} logspace (@var{base}, @var{limit}, @var{n})
  22. ## Similar to @code{linspace} except that the values are logarithmically
  23. ## spaced from
  24. ## @iftex
  25. ## @tex
  26. ## $10^{base}$ to $10^{limit}$.
  27. ## @end tex
  28. ## @end iftex
  29. ## @ifinfo
  30. ## 10^base to 10^limit.
  31. ## @end ifinfo
  32. ## 
  33. ## If @var{limit} is equal to
  34. ## @iftex
  35. ## @tex
  36. ## $\pi$,
  37. ## @end tex
  38. ## @end iftex
  39. ## @ifinfo
  40. ## pi,
  41. ## @end ifinfo
  42. ## the points are between
  43. ## @iftex
  44. ## @tex
  45. ## $10^{base}$ and $\pi$,
  46. ## @end tex
  47. ## @end iftex
  48. ## @ifinfo
  49. ## 10^base and pi,
  50. ## @end ifinfo
  51. ## @emph{not}
  52. ## @iftex
  53. ## @tex
  54. ## $10^{base}$ and $10^{\pi}$,
  55. ## @end tex
  56. ## @end iftex
  57. ## @ifinfo
  58. ## 10^base and 10^pi,
  59. ## @end ifinfo
  60. ## in order to  be compatible with the corresponding @sc{Matlab} function.
  61. ## @end deftypefn
  62.  
  63. ## See also: linspace
  64.  
  65. ## Author: jwe
  66.  
  67. function retval = logspace (x1, x2, n)
  68.  
  69.   if (nargin == 2)
  70.     npoints = 50;
  71.   elseif (nargin == 3)
  72.     if (length (n) == 1)
  73.       npoints = fix (n);
  74.     else
  75.       error ("logspace: arguments must be scalars");
  76.     endif
  77.   else
  78.     usage ("logspace (x1, x2 [, n])");
  79.   endif
  80.  
  81.   if (npoints < 2)
  82.     error ("logspace: npoints must be greater than 2");
  83.   endif
  84.  
  85.   if (length (x1) == 1 && length (x2) == 1)
  86.     x2_tmp = x2;
  87.     if (x2 == pi)
  88.       x2_tmp = log10 (pi);
  89.     endif
  90.     retval = 10 .^ (linspace (x1, x2_tmp, npoints));
  91.   else
  92.     error ("logspace: arguments must be scalars");
  93.   endif
  94.  
  95. endfunction
  96.