Mercurial > hg > octave-lyh
annotate scripts/general/logspace.m @ 10132:aa0f575cf39b
improve structfun's Matlab compatibility
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 19 Jan 2010 10:06:42 +0100 |
parents | f0c3d3fc4903 |
children | a8ce6bdecce5 |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2004, 2005, |
8920 | 2 ## 2006, 2007, 2008, 2009 John W. Eaton |
2313 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
2313 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
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 ## @tex | |
25 ## $10^{base}$ to $10^{limit}$. | |
26 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
27 ## @ifnottex |
3369 | 28 ## 10^base to 10^limit. |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
29 ## @end ifnottex |
3426 | 30 ## |
3369 | 31 ## If @var{limit} is equal to |
32 ## @tex | |
33 ## $\pi$, | |
34 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
35 ## @ifnottex |
3369 | 36 ## pi, |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
37 ## @end ifnottex |
3369 | 38 ## the points are between |
39 ## @tex | |
40 ## $10^{base}$ and $\pi$, | |
41 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
42 ## @ifnottex |
3369 | 43 ## 10^base and pi, |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
44 ## @end ifnottex |
3369 | 45 ## @emph{not} |
46 ## @tex | |
47 ## $10^{base}$ and $10^{\pi}$, | |
48 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
49 ## @ifnottex |
3369 | 50 ## 10^base and 10^pi, |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
51 ## @end ifnottex |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
52 ## in order to be compatible with the corresponding @sc{matlab} |
6630 | 53 ## function. |
54 ## | |
55 ## Also for compatibility, return the second argument if fewer than two | |
56 ## values are requested. | |
5642 | 57 ## @seealso{linspace} |
3369 | 58 ## @end deftypefn |
4 | 59 |
2314 | 60 ## Author: jwe |
61 | |
2311 | 62 function retval = logspace (x1, x2, n) |
4 | 63 |
64 if (nargin == 2) | |
65 npoints = 50; | |
66 elseif (nargin == 3) | |
67 if (length (n) == 1) | |
894 | 68 npoints = fix (n); |
4 | 69 else |
70 error ("logspace: arguments must be scalars"); | |
2325 | 71 endif |
4 | 72 else |
6046 | 73 print_usage (); |
4 | 74 endif |
75 | |
76 if (length (x1) == 1 && length (x2) == 1) | |
77 x2_tmp = x2; | |
78 if (x2 == pi) | |
79 x2_tmp = log10 (pi); | |
80 endif | |
415 | 81 retval = 10 .^ (linspace (x1, x2_tmp, npoints)); |
4 | 82 else |
83 error ("logspace: arguments must be scalars"); | |
84 endif | |
85 | |
86 endfunction | |
7411 | 87 |
88 %!test | |
89 %! x1 = logspace (1, 2); | |
90 %! x2 = logspace (1, 2, 10); | |
91 %! x3 = logspace (1, -2, 10); | |
92 %! x4 = logspace (1, pi, 10); | |
93 %! assert((size (x1) == [1, 50] && x1(1) == 10 && x1(50) == 100 | |
94 %! && size (x2) == [1, 10] && x2(1) == 10 && x2(10) == 100 | |
95 %! && size (x3) == [1, 10] && x3(1) == 10 && x3(10) == 0.01 | |
96 %! && size (x4) == [1, 10] && x4(1) == 10 && abs (x4(10) - pi) < sqrt (eps))); | |
97 | |
98 %!error logspace ([1, 2; 3, 4], 5, 6); | |
99 | |
100 %!error logspace (); | |
101 | |
102 %!error logspace (1, 2, 3, 4); | |
103 |