2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
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 |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
245
|
19 |
3369
|
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 |
3426
|
32 ## |
3369
|
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 |
5053
|
62 ## |
3407
|
63 ## @seealso{linspace} |
4
|
64 |
2314
|
65 ## Author: jwe |
|
66 |
2311
|
67 function retval = logspace (x1, x2, n) |
4
|
68 |
|
69 if (nargin == 2) |
|
70 npoints = 50; |
|
71 elseif (nargin == 3) |
|
72 if (length (n) == 1) |
894
|
73 npoints = fix (n); |
4
|
74 else |
|
75 error ("logspace: arguments must be scalars"); |
2325
|
76 endif |
4
|
77 else |
3456
|
78 usage ("logspace (x1, x2, n)"); |
4
|
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 |
415
|
90 retval = 10 .^ (linspace (x1, x2_tmp, npoints)); |
4
|
91 else |
|
92 error ("logspace: arguments must be scalars"); |
|
93 endif |
|
94 |
|
95 endfunction |