Mercurial > octave
annotate scripts/general/logspace.m @ 27919:1891570abac8
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2020.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 Jan 2020 22:29:51 -0500 |
parents | b442ec6dda5c |
children | bd51beb6205e |
rev | line source |
---|---|
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
1 ## Copyright (C) 1993-2020 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27898
diff
changeset
|
2 ## |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27898
diff
changeset
|
3 ## See the file COPYRIGHT.md in the top-level directory of this distribution |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27898
diff
changeset
|
4 ## or <https://octave.org/COPYRIGHT.html/>. |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27898
diff
changeset
|
5 ## |
2313 | 6 ## |
7 ## This file is part of Octave. | |
8 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24505
diff
changeset
|
9 ## Octave is free software: you can redistribute it and/or modify it |
2313 | 10 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24505
diff
changeset
|
11 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
12 ## (at your option) any later version. |
2313 | 13 ## |
14 ## Octave is distributed in the hope that it will be useful, but | |
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## GNU General Public License for more details. |
2313 | 18 ## |
19 ## You should have received a copy of the GNU General Public License | |
7016 | 20 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24505
diff
changeset
|
21 ## <https://www.gnu.org/licenses/>. |
245 | 22 |
3369 | 23 ## -*- texinfo -*- |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20158
diff
changeset
|
24 ## @deftypefn {} {} logspace (@var{a}, @var{b}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20158
diff
changeset
|
25 ## @deftypefnx {} {} logspace (@var{a}, @var{b}, @var{n}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20158
diff
changeset
|
26 ## @deftypefnx {} {} logspace (@var{a}, pi, @var{n}) |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
27 ## Return a row vector with @var{n} elements logarithmically spaced from |
3369 | 28 ## @tex |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
29 ## $10^{a}$ to $10^{b}$. |
3369 | 30 ## @end tex |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
31 ## @ifnottex |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
32 ## 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
|
33 ## @end ifnottex |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
34 ## |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
35 ## If @var{n} is unspecified it defaults to 50. |
3426 | 36 ## |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
37 ## If @var{b} is equal to |
3369 | 38 ## @tex |
39 ## $\pi$, | |
40 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
41 ## @ifnottex |
3369 | 42 ## pi, |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
43 ## @end ifnottex |
3369 | 44 ## the points are between |
45 ## @tex | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
46 ## $10^{a}$ and $\pi$, |
3369 | 47 ## @end tex |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
48 ## @ifnottex |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
49 ## 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
|
50 ## @end ifnottex |
3369 | 51 ## @emph{not} |
52 ## @tex | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
53 ## $10^{a}$ and $10^{\pi}$, |
3369 | 54 ## @end tex |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
55 ## @ifnottex |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
56 ## 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
|
57 ## @end ifnottex |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
58 ## in order to be compatible with the corresponding @sc{matlab} function. |
6630 | 59 ## |
24504
5188d936c79a
doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
60 ## Also for compatibility with @sc{matlab}, return the right-hand side of |
5188d936c79a
doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
61 ## the range |
5188d936c79a
doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
62 ## @tex |
5188d936c79a
doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
63 ## ($10^{b}$) |
5188d936c79a
doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
64 ## @end tex |
5188d936c79a
doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
65 ## @ifnottex |
5188d936c79a
doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
66 ## (10^@var{b}) |
5188d936c79a
doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
67 ## @end ifnottex |
5188d936c79a
doc: Documentation fixes for linspace, logspace, lookup (bug #52785).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
68 ## when just a single value is requested. |
5642 | 69 ## @seealso{linspace} |
3369 | 70 ## @end deftypefn |
4 | 71 |
25039
40a65b30fadf
maint: Match variable names in documentation to those in function prototype.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
72 function retval = logspace (a, b, n = 50) |
4 | 73 |
13288
497bb1cf7b15
logspace.m: Simplify function by using default values for arguments
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
74 if (nargin != 2 && nargin != 3) |
6046 | 75 print_usage (); |
4 | 76 endif |
77 | |
25039
40a65b30fadf
maint: Match variable names in documentation to those in function prototype.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
78 if (! (isscalar (a) && isscalar (b) && isscalar (n))) |
40a65b30fadf
maint: Match variable names in documentation to those in function prototype.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
79 error ("logspace: arguments A, B, and N must be scalars"); |
4 | 80 endif |
81 | |
13288
497bb1cf7b15
logspace.m: Simplify function by using default values for arguments
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
82 npoints = fix (n); |
497bb1cf7b15
logspace.m: Simplify function by using default values for arguments
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
83 |
25039
40a65b30fadf
maint: Match variable names in documentation to those in function prototype.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
84 if (b == pi) |
40a65b30fadf
maint: Match variable names in documentation to those in function prototype.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
85 b = log10 (pi); |
13288
497bb1cf7b15
logspace.m: Simplify function by using default values for arguments
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
86 endif |
497bb1cf7b15
logspace.m: Simplify function by using default values for arguments
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
87 |
25039
40a65b30fadf
maint: Match variable names in documentation to those in function prototype.
Rik <rik@octave.org>
parents:
24534
diff
changeset
|
88 retval = 10 .^ (linspace (a, b, npoints)); |
13288
497bb1cf7b15
logspace.m: Simplify function by using default values for arguments
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
89 |
4 | 90 endfunction |
7411 | 91 |
13288
497bb1cf7b15
logspace.m: Simplify function by using default values for arguments
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
92 |
7411 | 93 %!test |
94 %! 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
|
95 %! x2 = logspace (1, 2, 10.1); |
7411 | 96 %! x3 = logspace (1, -2, 10); |
97 %! x4 = logspace (1, pi, 10); | |
15795
9a10fa38ef01
logspace.m: fix tests
Philip Nienhuis <prnienhuis@users.sf.net>
parents:
14506
diff
changeset
|
98 %! 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
|
99 %! 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
|
100 %! 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
|
101 %! assert (size (x4) == [1, 10] && abs (x4(1) - 10) < eps && abs (x4(10) - pi) < sqrt (eps)); |
27435
a8a5d2e8807f
Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
102 |
a8a5d2e8807f
Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
103 ## Edge cases |
25237
ca022a8c4015
linspace: handle ranges with equal Inf endpoints (bug #53489)
Maor Shutman <maorus12@gmail.com>
parents:
25054
diff
changeset
|
104 %!assert (logspace (Inf, Inf, 3), [Inf, Inf, Inf]) |
27435
a8a5d2e8807f
Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
105 %!assert (logspace (-Inf, Inf, 3), [0, 1, Inf]) |
25268
592a4258b237
logspace.m: Update BIST tests to pass after cset ca022a8c4015.
Rik <rik@octave.org>
parents:
25237
diff
changeset
|
106 %!assert (logspace (Inf + 1i, Inf + 1i, 3), repmat (complex (-Inf,Inf), [1, 3])) |
592a4258b237
logspace.m: Update BIST tests to pass after cset ca022a8c4015.
Rik <rik@octave.org>
parents:
25237
diff
changeset
|
107 %!assert (logspace (-Inf + 1i, Inf + 1i, 3), [0, NaN + NaN * 1i, complex(-Inf, Inf)]) |
25237
ca022a8c4015
linspace: handle ranges with equal Inf endpoints (bug #53489)
Maor Shutman <maorus12@gmail.com>
parents:
25054
diff
changeset
|
108 %!assert (logspace (0, Inf, 3), [1, Inf, Inf]) |
ca022a8c4015
linspace: handle ranges with equal Inf endpoints (bug #53489)
Maor Shutman <maorus12@gmail.com>
parents:
25054
diff
changeset
|
109 %!assert (logspace (0, -Inf, 3), [1, 0, 0]) |
27435
a8a5d2e8807f
Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
110 %!assert (logspace (Inf, -Inf, 3), [Inf, 1, 0]) |
a8a5d2e8807f
Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
111 |
a8a5d2e8807f
Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
112 ## FIXME: These are bizarre corner cases for Matlab compatibility. See |
a8a5d2e8807f
Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
113 ## bug #56933. This is marked as "Won't Fix", but if linspace is updated at |
a8a5d2e8807f
Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
114 ## some point then these tests can be re-instated. |
a8a5d2e8807f
Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
115 ##%!assert (logspace (-Inf, 0, 3), [0, NaN, 1]) |
a8a5d2e8807f
Produce symmetric sequences for linspace (bug #56659).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
116 ##%!assert (logspace (Inf, 0, 3), [Inf, NaN, 1]) |
7411 | 117 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
118 ## Test input validation |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
119 %!error logspace () |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
120 %!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
|
121 %!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
|
122 %!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
|
123 %!error logspace (1, 2, [1, 2; 3, 4]) |