annotate scripts/linear-algebra/issymmetric.m @ 11431:0d9640d755b1

Improve docstrings for all isXXX functions. Use 'return true' rather than 'return 1'. Improve the cross-referencing through seealso links.
author Rik <octave@nomad.inbox5.com>
date Fri, 31 Dec 2010 13:20:44 -0800
parents fbd7843974fa
children fd0a3ac60b0e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8286
diff changeset
1 ## Copyright (C) 1996, 1997, 2002, 2003, 2004, 2005, 2006, 2007, 2008
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
2 ## John W. Eaton
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
3 ## Copyright (C) 2009 VZLU Prague
4026
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
4 ##
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
5 ## This file is part of Octave.
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
6 ##
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
7 ## 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
8 ## 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
9 ## 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
10 ## your option) any later version.
4026
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
11 ##
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
12 ## 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
13 ## WITHOUT ANY WARRANTY; without even the implied warranty of
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
15 ## General Public License for more details.
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
16 ##
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
17 ## 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
18 ## 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
19 ## <http://www.gnu.org/licenses/>.
4026
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
20
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
21 ## -*- texinfo -*-
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 10711
diff changeset
22 ## @deftypefn {Function File} {} issymmetric (@var{x})
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 10711
diff changeset
23 ## @deftypefnx {Function File} {} issymmetric (@var{x}, @var{tol})
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
24 ## Return true if @var{x} is a symmetric matrix within the tolerance specified
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 10711
diff changeset
25 ## by @var{tol}. The default tolerance is zero (uses faster code).
7265
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
26 ## Matrix @var{x} is considered symmetric if
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 10711
diff changeset
27 ## @code{norm (@var{x} - @var{x}.', Inf) / norm (@var{x}, Inf) < @var{tol}}.
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 10711
diff changeset
28 ## @seealso{ishermitian, isdefinite}
4026
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
29 ## @end deftypefn
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
30
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
31 ## Author: A. S. Hodel <scotte@eng.auburn.edu>
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
32 ## Created: August 1993
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
33 ## Adapted-By: jwe
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
34
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
35 function retval = issymmetric (x, tol = 0)
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
36
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
37 if (nargin < 1 || nargin > 2)
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
38 print_usage ();
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
39 endif
4026
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
40
10023
73fc43e01f4c allow issquare on arbitrary data
Jaroslav Hajek <highegg@gmail.com>
parents: 9869
diff changeset
41 retval = isnumeric (x) && issquare (x);
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
42 if (retval)
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
43 if (tol == 0)
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
44 retval = all ((x == x.')(:));
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
45 else
7265
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
46 norm_x = norm (x, inf);
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
47 retval = norm_x == 0 || norm (x - x.', inf) / norm_x <= tol;
4026
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
48 endif
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
49 endif
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
50
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
51 endfunction
7265
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
52
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
53 %!assert(issymmetric (1));
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
54 %!assert(!(issymmetric ([1, 2])));
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
55 %!assert(issymmetric ([]));
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
56 %!assert(issymmetric ([1, 2; 2, 1]));
7265
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
57 %!assert(!(issymmetric ("test")));
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
58 %!assert(issymmetric ([1, 2.1; 2, 1.1], 0.2));
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
59 %!assert(issymmetric ([1, 2i; 2i, 1]));
7265
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
60 %!assert(!(issymmetric ("t")));
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
61 %!assert(!(issymmetric (["te"; "et"])));
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
62 %!error issymmetric ([1, 2; 2, 1], 0, 0);
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
63 %!error issymmetric ();
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
64
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
65 %!test
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
66 %! s.a = 1;
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
67 %! assert(!(issymmetric (s)));