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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
6 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
7 ## This file is part of Octave.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
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
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
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
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
13 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
14 ## 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
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
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
18 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
19 ## 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
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
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 4
diff changeset
22
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
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
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
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
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
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
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3407
diff changeset
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
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
38 ## @tex
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
39 ## $\pi$,
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
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
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
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
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
44 ## the points are between
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
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
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
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
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
51 ## @emph{not}
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
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
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
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
0fcc8d65b571 [project @ 2007-05-16 15:32:09 by jwe]
jwe
parents: 6629
diff changeset
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
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5307
diff changeset
69 ## @seealso{linspace}
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2847
diff changeset
70 ## @end deftypefn
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
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
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
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
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5642
diff changeset
75 print_usage ();
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
76 endif
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
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
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
80 endif
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
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 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
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
90 endfunction
7411
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
91
13288
497bb1cf7b15 logspace.m: Simplify function by using default values for arguments
Rik <octave@nomad.inbox5.com>
parents: 12639
diff changeset
92
7411
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
93 %!test
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
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
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
96 %! x3 = logspace (1, -2, 10);
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
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
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
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])