Mercurial > octave
annotate scripts/linear-algebra/issymmetric.m @ 25054:6652d3823428 stable
maint: Update copyright dates in all source files.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 30 Mar 2018 09:19:05 -0400 |
parents | 194eb4bd202b |
children | 0f98040552de |
rev | line source |
---|---|
25054
6652d3823428
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1 ## Copyright (C) 1996-2018 John W. Eaton |
9869
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2 ## Copyright (C) 2009 VZLU Prague |
4026 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
6 ## Octave is free software: you can redistribute it and/or modify it |
4026 | 7 ## 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
|
8 ## 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
|
9 ## (at your option) any later version. |
4026 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
14 ## GNU General Public License for more details. |
4026 | 15 ## |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## 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
|
18 ## <https://www.gnu.org/licenses/>. |
4026 | 19 |
20 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
21 ## @deftypefn {} {} issymmetric (@var{A}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
22 ## @deftypefnx {} {} issymmetric (@var{A}, @var{tol}) |
18921
d0d0858cfab1
doc: Match docstring variable names to function variable names for linear-algebra m-files.
Rik <rik@octave.org>
parents:
18799
diff
changeset
|
23 ## Return true if @var{A} is a symmetric matrix within the tolerance specified |
d0d0858cfab1
doc: Match docstring variable names to function variable names for linear-algebra m-files.
Rik <rik@octave.org>
parents:
18799
diff
changeset
|
24 ## by @var{tol}. |
d0d0858cfab1
doc: Match docstring variable names to function variable names for linear-algebra m-files.
Rik <rik@octave.org>
parents:
18799
diff
changeset
|
25 ## |
d0d0858cfab1
doc: Match docstring variable names to function variable names for linear-algebra m-files.
Rik <rik@octave.org>
parents:
18799
diff
changeset
|
26 ## The default tolerance is zero (uses faster code). |
20160
03b9d17a2d95
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
27 ## |
18921
d0d0858cfab1
doc: Match docstring variable names to function variable names for linear-algebra m-files.
Rik <rik@octave.org>
parents:
18799
diff
changeset
|
28 ## Matrix @var{A} is considered symmetric if |
d0d0858cfab1
doc: Match docstring variable names to function variable names for linear-algebra m-files.
Rik <rik@octave.org>
parents:
18799
diff
changeset
|
29 ## @code{norm (@var{A} - @var{A}.', Inf) / norm (@var{A}, Inf) < @var{tol}}. |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
30 ## @seealso{ishermitian, isdefinite} |
4026 | 31 ## @end deftypefn |
32 | |
33 ## Author: A. S. Hodel <scotte@eng.auburn.edu> | |
34 ## Created: August 1993 | |
35 ## Adapted-By: jwe | |
36 | |
18921
d0d0858cfab1
doc: Match docstring variable names to function variable names for linear-algebra m-files.
Rik <rik@octave.org>
parents:
18799
diff
changeset
|
37 function retval = issymmetric (A, tol = 0) |
9869
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
38 |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
39 if (nargin < 1 || nargin > 2) |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
40 print_usage (); |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
41 endif |
4026 | 42 |
18921
d0d0858cfab1
doc: Match docstring variable names to function variable names for linear-algebra m-files.
Rik <rik@octave.org>
parents:
18799
diff
changeset
|
43 retval = (isnumeric (A) || islogical (A)) && issquare (A); |
9869
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
44 if (retval) |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
45 if (tol == 0) |
18421
7c0db9c4e454
issymmetric.m: Fix OOM when run on large sparse matrices (bug #41426)
David Spies <davidnspies@gmail.com>
parents:
17744
diff
changeset
|
46 ## Handle large sparse matrices as well as full ones |
18921
d0d0858cfab1
doc: Match docstring variable names to function variable names for linear-algebra m-files.
Rik <rik@octave.org>
parents:
18799
diff
changeset
|
47 retval = nnz (A != A.') == 0; |
9869
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
48 else |
18921
d0d0858cfab1
doc: Match docstring variable names to function variable names for linear-algebra m-files.
Rik <rik@octave.org>
parents:
18799
diff
changeset
|
49 norm_x = norm (A, inf); |
d0d0858cfab1
doc: Match docstring variable names to function variable names for linear-algebra m-files.
Rik <rik@octave.org>
parents:
18799
diff
changeset
|
50 retval = norm_x == 0 || norm (A - A.', inf) / norm_x <= tol; |
4026 | 51 endif |
52 endif | |
53 | |
54 endfunction | |
7265 | 55 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
56 |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
57 %!assert (issymmetric (1)) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
58 %!assert (! issymmetric ([1, 2])) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
59 %!assert (issymmetric ([])) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
60 %!assert (issymmetric ([1, 2; 2, 1])) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
61 %!assert (! (issymmetric ("test"))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
62 %!assert (issymmetric ([1, 2.1; 2, 1.1], 0.2)) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
63 %!assert (issymmetric ([1, 2i; 2i, 1])) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
64 %!assert (! (issymmetric ("t"))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
65 %!assert (! (issymmetric (["te"; "et"]))) |
18421
7c0db9c4e454
issymmetric.m: Fix OOM when run on large sparse matrices (bug #41426)
David Spies <davidnspies@gmail.com>
parents:
17744
diff
changeset
|
66 %!assert (issymmetric (speye (100000))) |
18799
9cf6d5868d21
issymmetric.m: Don't use final ';' in %!assert statement.
Rik <rik@octave.org>
parents:
18798
diff
changeset
|
67 %!assert (issymmetric (logical (eye (2)))) |
7265 | 68 |
69 %!test | |
70 %! s.a = 1; | |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
71 %! assert (! issymmetric (s)); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
72 |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
73 %!error issymmetric ([1, 2; 2, 1], 0, 0) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
74 %!error issymmetric () |