Mercurial > hg > octave-lyh
annotate scripts/general/logspace.m @ 10687:a8ce6bdecce5
Improve documentation strings.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Tue, 08 Jun 2010 20:22:38 -0700 |
parents | f0c3d3fc4903 |
children | c776f063fefe |
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 -*- |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
9211
diff
changeset
|
21 ## @deftypefn {Function File} {} logspace (@var{base}, @var{limit}) |
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
9211
diff
changeset
|
22 ## @deftypefnx {Function File} {} logspace (@var{base}, @var{limit}, @var{n}) |
3369 | 23 ## Similar to @code{linspace} except that the values are logarithmically |
24 ## spaced from | |
25 ## @tex | |
26 ## $10^{base}$ to $10^{limit}$. | |
27 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
28 ## @ifnottex |
3369 | 29 ## 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
|
30 ## @end ifnottex |
3426 | 31 ## |
3369 | 32 ## If @var{limit} is equal to |
33 ## @tex | |
34 ## $\pi$, | |
35 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
36 ## @ifnottex |
3369 | 37 ## pi, |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
38 ## @end ifnottex |
3369 | 39 ## the points are between |
40 ## @tex | |
41 ## $10^{base}$ and $\pi$, | |
42 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
43 ## @ifnottex |
3369 | 44 ## 10^base and pi, |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
45 ## @end ifnottex |
3369 | 46 ## @emph{not} |
47 ## @tex | |
48 ## $10^{base}$ and $10^{\pi}$, | |
49 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
50 ## @ifnottex |
3369 | 51 ## 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
|
52 ## @end ifnottex |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
53 ## in order to be compatible with the corresponding @sc{matlab} |
6630 | 54 ## function. |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
9211
diff
changeset
|
55 ## If @var{n} is unspecified it defaults to 50. |
6630 | 56 ## |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
9211
diff
changeset
|
57 ## Also for compatibility with @sc{matlab}, return the second argument if |
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
9211
diff
changeset
|
58 ## fewer than two values are requested. |
5642 | 59 ## @seealso{linspace} |
3369 | 60 ## @end deftypefn |
4 | 61 |
2314 | 62 ## Author: jwe |
63 | |
2311 | 64 function retval = logspace (x1, x2, n) |
4 | 65 |
66 if (nargin == 2) | |
67 npoints = 50; | |
68 elseif (nargin == 3) | |
69 if (length (n) == 1) | |
894 | 70 npoints = fix (n); |
4 | 71 else |
72 error ("logspace: arguments must be scalars"); | |
2325 | 73 endif |
4 | 74 else |
6046 | 75 print_usage (); |
4 | 76 endif |
77 | |
78 if (length (x1) == 1 && length (x2) == 1) | |
79 x2_tmp = x2; | |
80 if (x2 == pi) | |
81 x2_tmp = log10 (pi); | |
82 endif | |
415 | 83 retval = 10 .^ (linspace (x1, x2_tmp, npoints)); |
4 | 84 else |
85 error ("logspace: arguments must be scalars"); | |
86 endif | |
87 | |
88 endfunction | |
7411 | 89 |
90 %!test | |
91 %! x1 = logspace (1, 2); | |
92 %! x2 = logspace (1, 2, 10); | |
93 %! x3 = logspace (1, -2, 10); | |
94 %! x4 = logspace (1, pi, 10); | |
95 %! assert((size (x1) == [1, 50] && x1(1) == 10 && x1(50) == 100 | |
96 %! && size (x2) == [1, 10] && x2(1) == 10 && x2(10) == 100 | |
97 %! && size (x3) == [1, 10] && x3(1) == 10 && x3(10) == 0.01 | |
98 %! && size (x4) == [1, 10] && x4(1) == 10 && abs (x4(10) - pi) < sqrt (eps))); | |
99 | |
100 %!error logspace ([1, 2; 3, 4], 5, 6); | |
101 | |
102 %!error logspace (); | |
103 | |
104 %!error logspace (1, 2, 3, 4); | |
105 |