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 |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
2313
|
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 |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
245
|
18 |
3369
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {} logspace (@var{base}, @var{limit}, @var{n}) |
|
21 ## Similar to @code{linspace} except that the values are logarithmically |
|
22 ## spaced from |
|
23 ## @iftex |
|
24 ## @tex |
|
25 ## $10^{base}$ to $10^{limit}$. |
|
26 ## @end tex |
|
27 ## @end iftex |
|
28 ## @ifinfo |
|
29 ## 10^base to 10^limit. |
|
30 ## @end ifinfo |
3426
|
31 ## |
3369
|
32 ## If @var{limit} is equal to |
|
33 ## @iftex |
|
34 ## @tex |
|
35 ## $\pi$, |
|
36 ## @end tex |
|
37 ## @end iftex |
|
38 ## @ifinfo |
|
39 ## pi, |
|
40 ## @end ifinfo |
|
41 ## the points are between |
|
42 ## @iftex |
|
43 ## @tex |
|
44 ## $10^{base}$ and $\pi$, |
|
45 ## @end tex |
|
46 ## @end iftex |
|
47 ## @ifinfo |
|
48 ## 10^base and pi, |
|
49 ## @end ifinfo |
|
50 ## @emph{not} |
|
51 ## @iftex |
|
52 ## @tex |
|
53 ## $10^{base}$ and $10^{\pi}$, |
|
54 ## @end tex |
|
55 ## @end iftex |
|
56 ## @ifinfo |
|
57 ## 10^base and 10^pi, |
|
58 ## @end ifinfo |
6630
|
59 ## in order to be compatible with the corresponding @sc{Matlab} |
|
60 ## function. |
|
61 ## |
|
62 ## Also for compatibility, return the second argument if fewer than two |
|
63 ## values are requested. |
5642
|
64 ## @seealso{linspace} |
3369
|
65 ## @end deftypefn |
4
|
66 |
2314
|
67 ## Author: jwe |
|
68 |
2311
|
69 function retval = logspace (x1, x2, n) |
4
|
70 |
|
71 if (nargin == 2) |
|
72 npoints = 50; |
|
73 elseif (nargin == 3) |
|
74 if (length (n) == 1) |
894
|
75 npoints = fix (n); |
4
|
76 else |
|
77 error ("logspace: arguments must be scalars"); |
2325
|
78 endif |
4
|
79 else |
6046
|
80 print_usage (); |
4
|
81 endif |
|
82 |
|
83 if (length (x1) == 1 && length (x2) == 1) |
|
84 x2_tmp = x2; |
|
85 if (x2 == pi) |
|
86 x2_tmp = log10 (pi); |
|
87 endif |
415
|
88 retval = 10 .^ (linspace (x1, x2_tmp, npoints)); |
4
|
89 else |
|
90 error ("logspace: arguments must be scalars"); |
|
91 endif |
|
92 |
|
93 endfunction |