comparison scripts/general/logspace.m @ 4:b4df021f796c

[project @ 1993-08-08 01:26:08 by jwe] Initial revision
author jwe
date Sun, 08 Aug 1993 01:26:08 +0000
parents
children 16a24e76d6e0
comparison
equal deleted inserted replaced
3:9a4c07481e61 4:b4df021f796c
1 function retval = logspace (x1, x2, n)
2
3 # usage: logspace (x1, x2, n)
4 #
5 # Return a vector of n logarithmically equally spaced points between
6 # x1 and x2 inclusive.
7 #
8 # If the final argument is omitted, n = 50 is assumed.
9 #
10 # All three arguments must be scalars.
11 #
12 # Note that if if x2 is pi, the points are between 10^x1 and pi, NOT
13 # 10^x1 and 10^pi.
14 #
15 # Yes, this is pretty stupid, because you could achieve the same
16 # result with logspace (x1, log10 (pi)), but Matlab does this, and
17 # claims that is useful for signal processing applications.
18 #
19 # See also: linspace
20
21 if (nargin == 2)
22 npoints = 50;
23 elseif (nargin == 3)
24 if (length (n) == 1)
25 npoints = n;
26 else
27 error ("logspace: arguments must be scalars");
28 endif
29 else
30 error ("usage: logspace (x1, x2 [, n])");
31 endif
32
33 if (npoints < 2)
34 error ("logspace: npoints must be greater than 2");
35 endif
36
37 if (length (x1) == 1 && length (x2) == 1)
38 x2_tmp = x2;
39 if (x2 == pi)
40 x2_tmp = log10 (pi);
41 endif
42 retval = linspace (x1, x2_tmp, npoints);
43 for i = 1:npoints
44 retval(i) = 10 ^ retval(i);
45 endfor
46 else
47 error ("logspace: arguments must be scalars");
48 endif
49
50 endfunction