Mercurial > octave
annotate scripts/linear-algebra/isbanded.m @ 30558:83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
* isplaying.m, isrecording.m, isequal.m, isequaln.m, iscolormap.m,
is_valid_file_id.m, isdir.m, isstr.m, isbanded.m, isdefinite.m, isdiag.m,
ishermitian.m, issymmetric.m, istril.m, istriu.m, isdeployed.m, isfolder.m,
ismac.m, ismethod.m, ispc.m, isunix.m, isaxes.m, isfigure.m, isgraphics.m,
ishandle.m, ishold.m, ispref.m, isprime.m, isletter.m, isstring.m, isstrprop.m,
is_leap_year.m:
Use TF for output variable in documentation for isXXX functions.
Change variable name in code function prototype to match documentation.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 27 Dec 2021 16:07:08 -0800 |
parents | 7854d5752dd2 |
children | 83f9f8bda883 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
29358
0a5b15007766
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27978
diff
changeset
|
3 ## Copyright (C) 2014-2021 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
18900
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
7 ## |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
8 ## This file is part of Octave. |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
9 ## |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
18900
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
11 ## 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:
23220
diff
changeset
|
12 ## 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
|
13 ## (at your option) any later version. |
18900
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
14 ## |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
15 ## Octave is distributed in the hope that it will be useful, but |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
18 ## GNU General Public License for more details. |
18900
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
19 ## |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
20 ## You should have received a copy of the GNU General Public License |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
21 ## 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:
23220
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
18900
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
25 |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
26 ## -*- texinfo -*- |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
27 ## @deftypefn {} {@var{tf} =} isbanded (@var{A}, @var{lower}, @var{upper}) |
18921
d0d0858cfab1
doc: Match docstring variable names to function variable names for linear-algebra m-files.
Rik <rik@octave.org>
parents:
18904
diff
changeset
|
28 ## Return true if @var{A} is a matrix with entries confined between |
18900
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
29 ## @var{lower} diagonals below the main diagonal and @var{upper} diagonals |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
30 ## above the main diagonal. |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
31 ## |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
32 ## @var{lower} and @var{upper} must be non-negative integers. |
18904
9addb5ad9426
bandwidth.m: Add new function.
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
18900
diff
changeset
|
33 ## @seealso{isdiag, istril, istriu, bandwidth} |
18900
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
34 ## @end deftypefn |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
35 |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
36 function tf = isbanded (A, lower, upper) |
18900
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
37 |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
38 if (nargin != 3) |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
39 print_usage (); |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
40 endif |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
41 |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
42 if (! isreal (lower) || ! isreal (upper) || lower < 0 || upper < 0) |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
43 error ("isbanded: LOWER and UPPER must be non-negative integers"); |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
44 endif |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
45 |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
46 if (isempty (A)) |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
47 tf = []; |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
18921
diff
changeset
|
48 else |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
49 tf = (isnumeric (A) || islogical (A)) && ndims (A) == 2; |
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
50 if (tf) |
18900
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
51 [i, j] = find (A); |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
52 pupp = j >= i; |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
53 tf = all (j(pupp) - i(pupp) <= upper); |
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
54 if (tf) |
18900
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
55 plow = i >= j; |
30558
83aeaba707d8
doc: Use TF for output variable in documentation for isXXX functions in scripts/ directory.
Rik <rik@octave.org>
parents:
29359
diff
changeset
|
56 tf = all (i(plow) - j(plow) <= lower); |
18900
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
57 endif |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
58 endif |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
59 endif |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
60 |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
61 endfunction |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
62 |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
63 |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
64 %!assert (! isbanded ("string", 0, 0)) |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
65 %!assert (! isbanded (zeros (2,2,2), 0, 0)) |
20056
df3244834a50
fix tests now that assert ([]) fails
John W. Eaton <jwe@octave.org>
parents:
19833
diff
changeset
|
66 %!assert (isbanded ([], 0, 0), []) |
18900
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
67 %!assert (isbanded (1,0,0)) |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
68 %!assert (isbanded (1,10,10)) |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
69 |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
70 %!assert (isbanded ([1, 1],1,1)) |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
71 %!assert (isbanded ([1; 1],1,1)) |
28912
0de38a6ef693
maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
72 %!assert (isbanded (eye (10),0,0)) |
0de38a6ef693
maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
73 %!assert (isbanded (eye (10),1,1)) |
0de38a6ef693
maint: Use Octave convention of space after function name in scripts dir.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
74 %!assert (isbanded (i*eye (10),1,1)) |
18900
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
75 %!assert (isbanded (logical (eye (10)),1,1)) |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
76 |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
77 %! A = [2 3 0 0 0; 1 2 3 0 0; 0 1 2 3 0; 0 0 1 2 3; 0 0 0 1 2]; |
21580
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
78 %! assert (isbanded (A,1,1)); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
79 %! assert (! isbanded (A,0,1)); |
ecce63c99c3f
maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
80 %! assert (! isbanded (A,1,0)); |
18900
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
81 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
82 ## Test input validation |
28886
d8318c12d903
test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
83 %!error <Invalid call> isbanded () |
d8318c12d903
test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
84 %!error <Invalid call> isbanded (1) |
d8318c12d903
test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
85 %!error <Invalid call> isbanded (1,2) |
18900
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
86 %!error <LOWER and UPPER must be non-negative> isbanded (1, -1, 1) |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
87 %!error <LOWER and UPPER must be non-negative> isbanded (1, 1, -1) |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
88 %!error <LOWER and UPPER must be non-negative> isbanded (1, {1}, 1) |
49961d67e4b9
Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688).
Massimiliano Fasi <massimiliano.fasi@gmail.com>
parents:
diff
changeset
|
89 %!error <LOWER and UPPER must be non-negative> isbanded (1, 1, {1}) |