Mercurial > octave-libgccjit
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 |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 1996, 1997, 2002, 2003, 2004, 2005, 2006, 2007, 2008 |
7017 | 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 | 4 ## |
5 ## This file is part of Octave. | |
6 ## | |
7 ## Octave is free software; you can redistribute it and/or modify it | |
8 ## under the terms of the GNU General Public License as published by | |
7016 | 9 ## the Free Software Foundation; either version 3 of the License, or (at |
10 ## your option) any later version. | |
4026 | 11 ## |
12 ## Octave is distributed in the hope that it will be useful, but | |
13 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 ## General Public License for more details. | |
16 ## | |
17 ## You should have received a copy of the GNU General Public License | |
7016 | 18 ## along with Octave; see the file COPYING. If not, see |
19 ## <http://www.gnu.org/licenses/>. | |
4026 | 20 |
21 ## -*- texinfo -*- | |
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 | 26 ## Matrix @var{x} is considered symmetric if |
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 | 29 ## issquare, isvector} |
4026 | 30 ## @end deftypefn |
31 | |
32 ## Author: A. S. Hodel <scotte@eng.auburn.edu> | |
33 ## Created: August 1993 | |
34 ## Adapted-By: jwe | |
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 | 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 | 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 | 49 endif |
50 endif | |
51 | |
52 endfunction | |
7265 | 53 |
54 %!assert(issymmetric (1)); | |
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 | 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 | 61 %!assert(!(issymmetric ("t"))); |
62 %!assert(!(issymmetric (["te"; "et"]))); | |
63 %!error issymmetric ([1, 2; 2, 1], 0, 0); | |
64 %!error issymmetric (); | |
65 | |
66 %!test | |
67 %! s.a = 1; | |
68 %! assert(!(issymmetric (s))); |