7017
|
1 ## Copyright (C) 1996, 1997, 2002, 2003, 2004, 2005, 2006, 2007 |
|
2 ## John W. Eaton |
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 -*- |
|
21 ## @deftypefn {Function File} {} issymmetric (@var{x}, @var{tol}) |
|
22 ## If @var{x} is symmetric within the tolerance specified by @var{tol}, |
|
23 ## then return the dimension of @var{x}. Otherwise, return 0. If |
|
24 ## @var{tol} is omitted, use a tolerance equal to the machine precision. |
7265
|
25 ## Matrix @var{x} is considered symmetric if |
|
26 ## @code{norm (@var{x} - @var{x}.', inf) / norm (@var{x}, inf) < @var{tol}}. |
|
27 ## @seealso{size, rows, columns, length, ishermitian, ismatrix, isscalar, |
5642
|
28 ## issquare, isvector} |
4026
|
29 ## @end deftypefn |
|
30 |
|
31 ## Author: A. S. Hodel <scotte@eng.auburn.edu> |
|
32 ## Created: August 1993 |
|
33 ## Adapted-By: jwe |
|
34 |
7265
|
35 function retval = issymmetric (x, tol) |
4026
|
36 |
|
37 if (nargin == 1 || nargin == 2) |
|
38 retval = issquare (x); |
|
39 if (retval != 0) |
|
40 if (nargin == 1) |
|
41 tol = eps; |
|
42 endif |
7265
|
43 norm_x = norm (x, inf); |
|
44 if (norm_x != 0 && norm (x - x.', inf) / norm_x > tol) |
4026
|
45 retval = 0; |
|
46 endif |
|
47 endif |
|
48 else |
6046
|
49 print_usage (); |
4026
|
50 endif |
|
51 |
|
52 endfunction |
7265
|
53 |
|
54 %!assert(issymmetric (1)); |
|
55 %!assert(!(issymmetric ([1, 2]))); |
|
56 %!assert(!(issymmetric ([]))); |
|
57 %!assert(issymmetric ([1, 2; 2, 1]) == 2); |
|
58 %!assert(!(issymmetric ("test"))); |
|
59 %!assert(issymmetric ([1, 2.1; 2, 1.1], 0.2) == 2); |
|
60 %!assert(!issymmetric ([1, 2i; -2i, 1])); |
|
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))); |