Mercurial > hg > octave-lyh
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 |
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 -*- | |
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 | 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 | 29 ## @end deftypefn |
30 | |
31 ## Author: A. S. Hodel <scotte@eng.auburn.edu> | |
32 ## Created: August 1993 | |
33 ## Adapted-By: jwe | |
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 | 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 | 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 | 48 endif |
49 endif | |
50 | |
51 endfunction | |
7265 | 52 |
53 %!assert(issymmetric (1)); | |
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 | 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 | 60 %!assert(!(issymmetric ("t"))); |
61 %!assert(!(issymmetric (["te"; "et"]))); | |
62 %!error issymmetric ([1, 2; 2, 1], 0, 0); | |
63 %!error issymmetric (); | |
64 | |
65 %!test | |
66 %! s.a = 1; | |
67 %! assert(!(issymmetric (s))); |