Mercurial > octave-libgccjit
annotate scripts/linear-algebra/issymmetric.m @ 18921:d0d0858cfab1
doc: Match docstring variable names to function variable names for linear-algebra m-files.
* isbanded.m, isdefinite.m, isdiag.m, ishermitian.m, issymmetric.m, istril.m,
istriu.m: Use 'A' for input matrix in linear algebra routines. Change docstrings
from 'x' to 'A'.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 14 Jul 2014 08:54:45 -0700 |
parents | 9cf6d5868d21 |
children |
rev | line source |
---|---|
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
14868
diff
changeset
|
1 ## Copyright (C) 1996-2013 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 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## 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 | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
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 |
18 ## <http://www.gnu.org/licenses/>. | |
4026 | 19 |
20 ## -*- texinfo -*- | |
18921
d0d0858cfab1
doc: Match docstring variable names to function variable names for linear-algebra m-files.
Rik <rik@octave.org>
parents:
18799
diff
changeset
|
21 ## @deftypefn {Function File} {} issymmetric (@var{A}) |
d0d0858cfab1
doc: Match docstring variable names to function variable names for linear-algebra m-files.
Rik <rik@octave.org>
parents:
18799
diff
changeset
|
22 ## @deftypefnx {Function File} {} issymmetric (@var{A}, @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
|
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). |
d0d0858cfab1
doc: Match docstring variable names to function variable names for linear-algebra m-files.
Rik <rik@octave.org>
parents:
18799
diff
changeset
|
27 ## 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
|
28 ## @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
|
29 ## @seealso{ishermitian, isdefinite} |
4026 | 30 ## @end deftypefn |
31 | |
32 ## Author: A. S. Hodel <scotte@eng.auburn.edu> | |
33 ## Created: August 1993 | |
34 ## Adapted-By: jwe | |
35 | |
18921
d0d0858cfab1
doc: Match docstring variable names to function variable names for linear-algebra m-files.
Rik <rik@octave.org>
parents:
18799
diff
changeset
|
36 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
|
37 |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
38 if (nargin < 1 || nargin > 2) |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
39 print_usage (); |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
40 endif |
4026 | 41 |
18921
d0d0858cfab1
doc: Match docstring variable names to function variable names for linear-algebra m-files.
Rik <rik@octave.org>
parents:
18799
diff
changeset
|
42 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
|
43 if (retval) |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
44 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
|
45 ## 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
|
46 retval = nnz (A != A.') == 0; |
9869
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
47 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
|
48 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
|
49 retval = norm_x == 0 || norm (A - A.', inf) / norm_x <= tol; |
4026 | 50 endif |
51 endif | |
52 | |
53 endfunction | |
7265 | 54 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
55 |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
56 %!assert (issymmetric (1)) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
57 %!assert (! issymmetric ([1, 2])) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
58 %!assert (issymmetric ([])) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
59 %!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
|
60 %!assert (! (issymmetric ("test"))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
61 %!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
|
62 %!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
|
63 %!assert (! (issymmetric ("t"))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
64 %!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
|
65 %!assert (issymmetric (speye (100000))) |
18799
9cf6d5868d21
issymmetric.m: Don't use final ';' in %!assert statement.
Rik <rik@octave.org>
parents:
18798
diff
changeset
|
66 %!assert (issymmetric (logical (eye (2)))) |
7265 | 67 |
68 %!test | |
69 %! 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
|
70 %! assert (! issymmetric (s)); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
71 |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
72 %!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
|
73 %!error issymmetric () |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
74 |