diff scripts/general/issymmetric.m @ 7265:7da4a5262e2e

[project @ 2007-12-06 19:16:47 by jwe]
author jwe
date Thu, 06 Dec 2007 19:16:48 +0000
parents a1dbe9d80eee
children add731f4024d
line wrap: on
line diff
--- a/scripts/general/issymmetric.m
+++ b/scripts/general/issymmetric.m
@@ -22,7 +22,9 @@
 ## If @var{x} is symmetric within the tolerance specified by @var{tol},
 ## then return the dimension of @var{x}.  Otherwise, return 0.  If
 ## @var{tol} is omitted, use a tolerance equal to the machine precision.
-## @seealso{size, rows, columns, length, ismatrix, isscalar,
+## Matrix @var{x} is considered symmetric if
+## @code{norm (@var{x} - @var{x}.', inf) / norm (@var{x}, inf) < @var{tol}}.
+## @seealso{size, rows, columns, length, ishermitian, ismatrix, isscalar,
 ## issquare, isvector}
 ## @end deftypefn
 
@@ -30,7 +32,7 @@
 ## Created: August 1993
 ## Adapted-By: jwe
 
-function retval = issymmetric (x,tol)
+function retval = issymmetric (x, tol)
 
   if (nargin == 1 || nargin == 2)
     retval = issquare (x);
@@ -38,8 +40,8 @@
       if (nargin == 1)
         tol = eps;
       endif
-      norm_x = norm (x);
-      if (norm_x != 0 && norm (x - x') / norm_x > tol)
+      norm_x = norm (x, inf);
+      if (norm_x != 0 && norm (x - x.', inf) / norm_x > tol)
         retval = 0;
       endif
     endif
@@ -48,3 +50,19 @@
   endif
 
 endfunction
+
+%!assert(issymmetric (1));
+%!assert(!(issymmetric ([1, 2])));
+%!assert(!(issymmetric ([])));
+%!assert(issymmetric ([1, 2; 2, 1]) == 2);
+%!assert(!(issymmetric ("test")));
+%!assert(issymmetric ([1, 2.1; 2, 1.1], 0.2) == 2);
+%!assert(!issymmetric ([1, 2i; -2i, 1]));
+%!assert(!(issymmetric ("t")));
+%!assert(!(issymmetric (["te"; "et"])));
+%!error issymmetric ([1, 2; 2, 1], 0, 0);
+%!error issymmetric ();
+
+%!test
+%! s.a = 1;
+%! assert(!(issymmetric (s)));