Mercurial > hg > octave-nkf
annotate scripts/general/logspace.m @ 12541:dd2c70b30f28
Add tests for ifftshift.m
author | Robert T. Short <octave@phaselockedsystems.com.com> |
---|---|
date | Sat, 26 Mar 2011 06:50:12 -0700 |
parents | c792872f8942 |
children | 4d777e05d47c |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1993-2011 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 -*- |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
9211
diff
changeset
|
20 ## @deftypefn {Function File} {} logspace (@var{base}, @var{limit}) |
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
9211
diff
changeset
|
21 ## @deftypefnx {Function File} {} logspace (@var{base}, @var{limit}, @var{n}) |
3369 | 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. |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
9211
diff
changeset
|
54 ## If @var{n} is unspecified it defaults to 50. |
6630 | 55 ## |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
56 ## Also for compatibility with @sc{matlab}, return the second argument if |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
9211
diff
changeset
|
57 ## fewer than two values are requested. |
5642 | 58 ## @seealso{linspace} |
3369 | 59 ## @end deftypefn |
4 | 60 |
2314 | 61 ## Author: jwe |
62 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
63 function retval = logspace (base, limit, n) |
4 | 64 |
65 if (nargin == 2) | |
66 npoints = 50; | |
67 elseif (nargin == 3) | |
68 if (length (n) == 1) | |
894 | 69 npoints = fix (n); |
4 | 70 else |
71 error ("logspace: arguments must be scalars"); | |
2325 | 72 endif |
4 | 73 else |
6046 | 74 print_usage (); |
4 | 75 endif |
76 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
77 if (length (base) == 1 && length (limit) == 1) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
78 if (limit == pi) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
79 limit = log10 (pi); |
4 | 80 endif |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
81 retval = 10 .^ (linspace (base, limit, 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 |