Mercurial > octave-nkf
annotate scripts/linear-algebra/issymmetric.m @ 18833:9cf6d5868d21
issymmetric.m: Don't use final ';' in %!assert statement.
* issymmetric.m: Don't use final ';' in %!assert statement.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 03 Jun 2014 22:11:01 -0700 |
parents | b422ba27951c |
children | d0d0858cfab1 |
rev | line source |
---|---|
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
14868
diff
changeset
|
1 ## Copyright (C) 1996-2013 John W. Eaton |
9869
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
2 ## Copyright (C) 2009 VZLU Prague |
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 -*- | |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
21 ## @deftypefn {Function File} {} issymmetric (@var{x}) |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
22 ## @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
|
23 ## 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
|
24 ## by @var{tol}. The default tolerance is zero (uses faster code). |
7265 | 25 ## Matrix @var{x} is considered symmetric if |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10711
diff
changeset
|
26 ## @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
|
27 ## @seealso{ishermitian, isdefinite} |
4026 | 28 ## @end deftypefn |
29 | |
30 ## Author: A. S. Hodel <scotte@eng.auburn.edu> | |
31 ## Created: August 1993 | |
32 ## Adapted-By: jwe | |
33 | |
9869
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
34 function retval = issymmetric (x, tol = 0) |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
35 |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
36 if (nargin < 1 || nargin > 2) |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
37 print_usage (); |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
38 endif |
4026 | 39 |
18832
b422ba27951c
Made issymmetric (issymmetric.m) work for logical matrices (Bug #42485)
David Spies <dnspies@gmail.com>
parents:
18421
diff
changeset
|
40 retval = (isnumeric (x) || islogical (x)) && issquare (x); |
9869
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
41 if (retval) |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
42 if (tol == 0) |
18421
7c0db9c4e454
issymmetric.m: Fix OOM when run on large sparse matrices (bug #41426)
David Spies <davidnspies@gmail.com>
parents:
17744
diff
changeset
|
43 ## Handle large sparse matrices as well as full ones |
7c0db9c4e454
issymmetric.m: Fix OOM when run on large sparse matrices (bug #41426)
David Spies <davidnspies@gmail.com>
parents:
17744
diff
changeset
|
44 retval = nnz (x != x.') == 0; |
9869
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 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
53 |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
54 %!assert (issymmetric (1)) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
55 %!assert (! issymmetric ([1, 2])) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
56 %!assert (issymmetric ([])) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
57 %!assert (issymmetric ([1, 2; 2, 1])) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
58 %!assert (! (issymmetric ("test"))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
59 %!assert (issymmetric ([1, 2.1; 2, 1.1], 0.2)) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
60 %!assert (issymmetric ([1, 2i; 2i, 1])) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
61 %!assert (! (issymmetric ("t"))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
62 %!assert (! (issymmetric (["te"; "et"]))) |
18421
7c0db9c4e454
issymmetric.m: Fix OOM when run on large sparse matrices (bug #41426)
David Spies <davidnspies@gmail.com>
parents:
17744
diff
changeset
|
63 %!assert (issymmetric (speye (100000))) |
18833
9cf6d5868d21
issymmetric.m: Don't use final ';' in %!assert statement.
Rik <rik@octave.org>
parents:
18832
diff
changeset
|
64 %!assert (issymmetric (logical (eye (2)))) |
7265 | 65 |
66 %!test | |
67 %! s.a = 1; | |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
68 %! assert (! issymmetric (s)); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
69 |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
70 %!error issymmetric ([1, 2; 2, 1], 0, 0) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
71 %!error issymmetric () |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
72 |