home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts.fat / general / logspace.m < prev    next >
Text File  |  1999-04-29  |  2KB  |  69 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. ## usage: logspace (x1, x2, n)
  21. ##
  22. ## Return a vector of n logarithmically equally spaced points between
  23. ## 10^x1 and 10^x2 inclusive.
  24. ##
  25. ## If the final argument is omitted, n = 50 is assumed.
  26. ##
  27. ## All three arguments must be scalars.
  28. ##
  29. ## Note that if if x2 is pi, the points are between 10^x1 and pi, NOT
  30. ## 10^x1 and 10^pi.
  31. ##
  32. ## Yes, this is pretty stupid, because you could achieve the same
  33. ## result with logspace (x1, log10 (pi)), but Matlab does this, and
  34. ## claims that is useful for signal processing applications.
  35. ##
  36. ## See also: linspace
  37.  
  38. ## Author: jwe
  39.  
  40. function retval = logspace (x1, x2, n)
  41.  
  42.   if (nargin == 2)
  43.     npoints = 50;
  44.   elseif (nargin == 3)
  45.     if (length (n) == 1)
  46.       npoints = fix (n);
  47.     else
  48.       error ("logspace: arguments must be scalars");
  49.     endif
  50.   else
  51.     usage ("logspace (x1, x2 [, n])");
  52.   endif
  53.  
  54.   if (npoints < 2)
  55.     error ("logspace: npoints must be greater than 2");
  56.   endif
  57.  
  58.   if (length (x1) == 1 && length (x2) == 1)
  59.     x2_tmp = x2;
  60.     if (x2 == pi)
  61.       x2_tmp = log10 (pi);
  62.     endif
  63.     retval = 10 .^ (linspace (x1, x2_tmp, npoints));
  64.   else
  65.     error ("logspace: arguments must be scalars");
  66.   endif
  67.  
  68. endfunction
  69.