Mercurial > hg > octave-nkf
annotate scripts/general/logspace.m @ 19669:c2031ad6dbe7
Fix octave header includes in audiodevinfo
* audiodevinfo.cc: change includes to use local octave headers
author | Vytautas Jančauskas <unaudio@gmail.com> |
---|---|
date | Wed, 11 Sep 2013 21:32:14 +0300 |
parents | 9a10fa38ef01 |
children | d63878346099 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13288
diff
changeset
|
1 ## Copyright (C) 1993-2012 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 -*- |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
20 ## @deftypefn {Function File} {} logspace (@var{a}, @var{b}) |
14504
ecd4b048f98c
doc: Fix typo in logspace.m docstring (bug #36024)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
21 ## @deftypefnx {Function File} {} logspace (@var{a}, @var{b}, @var{n}) |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
22 ## @deftypefnx {Function File} {} logspace (@var{a}, pi, @var{n}) |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
23 ## Return a row vector with @var{n} elements logarithmically spaced from |
3369 | 24 ## @tex |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
25 ## $10^{a}$ to $10^{b}$. |
3369 | 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 |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
28 ## 10^@var{a} to 10^@var{b}. |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
29 ## @end ifnottex |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
30 ## If @var{n} is unspecified it defaults to 50. |
3426 | 31 ## |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
32 ## If @var{b} is equal to |
3369 | 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 | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
41 ## $10^{a}$ and $\pi$, |
3369 | 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 |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
44 ## 10^@var{a} 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 | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
48 ## $10^{a}$ and $10^{\pi}$, |
3369 | 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 |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
51 ## 10^@var{a} 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 |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
53 ## in order to be compatible with the corresponding @sc{matlab} function. |
6630 | 54 ## |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
55 ## Also for compatibility with @sc{matlab}, return the second argument @var{b} |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
56 ## if fewer than two values are requested. |
5642 | 57 ## @seealso{linspace} |
3369 | 58 ## @end deftypefn |
4 | 59 |
2314 | 60 ## Author: jwe |
61 | |
13288
497bb1cf7b15
logspace.m: Simplify function by using default values for arguments
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
62 function retval = logspace (base, limit, n = 50) |
4 | 63 |
13288
497bb1cf7b15
logspace.m: Simplify function by using default values for arguments
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
64 if (nargin != 2 && nargin != 3) |
6046 | 65 print_usage (); |
4 | 66 endif |
67 | |
13288
497bb1cf7b15
logspace.m: Simplify function by using default values for arguments
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
68 if (! (isscalar (base) && isscalar (limit) && isscalar (n))) |
497bb1cf7b15
logspace.m: Simplify function by using default values for arguments
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
69 error ("logspace: arguments BASE, LIMIT, and N must be scalars"); |
4 | 70 endif |
71 | |
13288
497bb1cf7b15
logspace.m: Simplify function by using default values for arguments
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
72 npoints = fix (n); |
497bb1cf7b15
logspace.m: Simplify function by using default values for arguments
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
73 |
497bb1cf7b15
logspace.m: Simplify function by using default values for arguments
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
74 if (limit == pi) |
497bb1cf7b15
logspace.m: Simplify function by using default values for arguments
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
75 limit = log10 (pi); |
497bb1cf7b15
logspace.m: Simplify function by using default values for arguments
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
76 endif |
497bb1cf7b15
logspace.m: Simplify function by using default values for arguments
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
77 |
497bb1cf7b15
logspace.m: Simplify function by using default values for arguments
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
78 retval = 10 .^ (linspace (base, limit, npoints)); |
497bb1cf7b15
logspace.m: Simplify function by using default values for arguments
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
79 |
4 | 80 endfunction |
7411 | 81 |
13288
497bb1cf7b15
logspace.m: Simplify function by using default values for arguments
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
82 |
7411 | 83 %!test |
84 %! x1 = logspace (1, 2); | |
13288
497bb1cf7b15
logspace.m: Simplify function by using default values for arguments
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
85 %! x2 = logspace (1, 2, 10.1); |
7411 | 86 %! x3 = logspace (1, -2, 10); |
87 %! x4 = logspace (1, pi, 10); | |
15795
9a10fa38ef01
logspace.m: fix tests
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14506
diff
changeset
|
88 %! assert (size (x1) == [1, 50] && abs (x1(1) - 10) < eps && abs (x1(50) - 100) < eps); |
9a10fa38ef01
logspace.m: fix tests
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14506
diff
changeset
|
89 %! assert (size (x2) == [1, 10] && abs (x2(1) - 10) < eps && abs (x2(10) - 100) < eps); |
9a10fa38ef01
logspace.m: fix tests
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14506
diff
changeset
|
90 %! assert (size (x3) == [1, 10] && abs (x3(1) - 10) < eps && abs (x3(10) - 0.01) < eps); |
9a10fa38ef01
logspace.m: fix tests
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14506
diff
changeset
|
91 %! assert (size (x4) == [1, 10] && abs (x4(1) - 10) < eps && abs (x4(10) - pi) < sqrt (eps)); |
7411 | 92 |
13288
497bb1cf7b15
logspace.m: Simplify function by using default values for arguments
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
93 %% Test input validation |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
94 %!error logspace () |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
95 %!error logspace (1, 2, 3, 4) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
96 %!error logspace ([1, 2; 3, 4], 5, 6) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
97 %!error logspace (1, [1, 2; 3, 4], 6) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
98 %!error logspace (1, 2, [1, 2; 3, 4]) |
7411 | 99 |