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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
3 ##
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
4 ## This file is part of Octave.
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
5 ##
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
6 ## Octave is free software; you can redistribute it and/or modify it
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
7 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
8 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
9 ## your option) any later version.
4026
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
10 ##
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
11 ## Octave is distributed in the hope that it will be useful, but
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
14 ## General Public License for more details.
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
15 ##
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
16 ## 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: 6046
diff changeset
17 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
18 ## <http://www.gnu.org/licenses/>.
4026
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
19
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
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
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
30 ## @end deftypefn
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
31
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
32 ## Author: A. S. Hodel <scotte@eng.auburn.edu>
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
33 ## Created: August 1993
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
34 ## Adapted-By: jwe
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
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
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
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
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
50 endif
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
51 endif
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
52
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
53 endfunction
7265
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
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
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
67
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
68 %!test
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
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