annotate scripts/linear-algebra/issymmetric.m @ 9869:ecd750d1eabd

move issymmetric & isdefinite to linear-algebra, create ishermitian
author Jaroslav Hajek <highegg@gmail.com>
date Tue, 24 Nov 2009 15:02:04 +0100
parents scripts/general/issymmetric.m@eb63fbe60fab
children 73fc43e01f4c
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 -*-
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
22 ## @deftypefn {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
23 ## Return true if @var{x} is a symmetric matrix within the tolerance specified
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
24 ## by @var{tol}, otherwise return false. The default tolerance is zero (uses
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
25 ## 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
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
27 ## @code{norm (@var{x} - @var{x}.', inf) / norm (@var{x}, inf) < @var{tol}}.
8286
6f2d95255911 fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 7795
diff changeset
28 ## @seealso{size, rows, columns, length, ismatrix, isscalar,
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5307
diff changeset
29 ## issquare, isvector}
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
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
36 function retval = issymmetric (x, tol = 0)
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
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
42 retval = issquare (x);
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)
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
45 retval = all ((x == x.')(:));
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
46 else
7265
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
47 norm_x = norm (x, inf);
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
48 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
49 endif
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
8cb8eff3f44c [project @ 2002-08-09 06:54:46 by jwe]
jwe
parents:
diff changeset
52 endfunction
7265
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
53
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
54 %!assert(issymmetric (1));
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
55 %!assert(!(issymmetric ([1, 2])));
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
56 %!assert(issymmetric ([]));
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
57 %!assert(issymmetric ([1, 2; 2, 1]));
7265
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
58 %!assert(!(issymmetric ("test")));
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
59 %!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
60 %!assert(issymmetric ([1, 2i; 2i, 1]));
7265
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
61 %!assert(!(issymmetric ("t")));
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
62 %!assert(!(issymmetric (["te"; "et"])));
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
63 %!error issymmetric ([1, 2; 2, 1], 0, 0);
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
64 %!error issymmetric ();
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
65
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
66 %!test
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
67 %! s.a = 1;
7da4a5262e2e [project @ 2007-12-06 19:16:47 by jwe]
jwe
parents: 7017
diff changeset
68 %! assert(!(issymmetric (s)));