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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
2 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
3 ## This file is part of Octave.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
4 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6630
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6630
diff changeset
8 ## your option) any later version.
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
9 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
13 ## General Public License for more details.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
14 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6630
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6630
diff changeset
17 ## <http://www.gnu.org/licenses/>.
245
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 4
diff changeset
18
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
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
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
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
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
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
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3407
diff changeset
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
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
33 ## @tex
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
34 ## $\pi$,
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
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
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
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
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
39 ## the points are between
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
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
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
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
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
46 ## @emph{not}
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
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
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
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
0fcc8d65b571 [project @ 2007-05-16 15:32:09 by jwe]
jwe
parents: 6629
diff changeset
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
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5307
diff changeset
57 ## @seealso{linspace}
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
58 ## @end deftypefn
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
59
2314
949ab8eba8bc [project @ 1996-07-12 03:58:02 by jwe]
jwe
parents: 2313
diff changeset
60 ## Author: jwe
949ab8eba8bc [project @ 1996-07-12 03:58:02 by jwe]
jwe
parents: 2313
diff changeset
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
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
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
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5642
diff changeset
65 print_usage ();
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
66 endif
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
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
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
70 endif
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
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
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
80 endfunction
7411
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
81
13288
497bb1cf7b15 logspace.m: Simplify function by using default values for arguments
Rik <octave@nomad.inbox5.com>
parents: 12639
diff changeset
82
7411
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
83 %!test
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
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
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
86 %! x3 = logspace (1, -2, 10);
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
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
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
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
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
99