Mercurial > hg > octave-lyh
annotate scripts/linear-algebra/ishermitian.m @ 17526:05bed3576091
Fix int16 type comments
author | LYH <lyh.kernel@gmail.com> |
---|---|
date | Fri, 27 Sep 2013 04:18:59 +0800 |
parents | 5d3a684236b0 |
children |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1 ## Copyright (C) 1996-2012 John W. Eaton |
9869
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
2 ## Copyright (C) 2009 VZLU Prague |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
3 ## |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
4 ## This file is part of Octave. |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
5 ## |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
6 ## Octave is free software; you can redistribute it and/or modify it |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
7 ## under the terms of the GNU General Public License as published by |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
9 ## your option) any later version. |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
10 ## |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
11 ## Octave is distributed in the hope that it will be useful, but |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
14 ## General Public License for more details. |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
15 ## |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
16 ## You should have received a copy of the GNU General Public License |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
17 ## along with Octave; see the file COPYING. If not, see |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
18 ## <http://www.gnu.org/licenses/>. |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
19 |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
20 ## -*- texinfo -*- |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
21 ## @deftypefn {Function File} {} ishermitian (@var{x}) |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
22 ## @deftypefnx {Function File} {} ishermitian (@var{x}, @var{tol}) |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
23 ## Return true if @var{x} is Hermitian within the tolerance specified by |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
24 ## @var{tol}. |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
25 ## The default tolerance is zero (uses faster code). |
9869
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
26 ## Matrix @var{x} is considered symmetric if |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
10793
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:
10793
diff
changeset
|
28 ## @seealso{issymmetric, isdefinite} |
9869
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
29 ## @end deftypefn |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
30 |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
31 ## Author: A. S. Hodel <scotte@eng.auburn.edu> |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
32 ## Created: August 1993 |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
33 ## Adapted-By: jwe |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
34 |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
35 function retval = ishermitian (x, tol = 0) |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
36 |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
37 if (nargin < 1 || nargin > 2) |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
38 print_usage (); |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
39 endif |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
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:
diff
changeset
|
42 if (retval) |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
43 if (tol == 0) |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
44 retval = all ((x == x')(:)); |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
45 else |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
46 norm_x = norm (x, inf); |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
47 retval = norm_x == 0 || norm (x - x', inf) / norm_x <= tol; |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
48 endif |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
49 endif |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
50 |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
51 endfunction |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
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 (ishermitian (1)) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
55 %!assert (! ishermitian ([1, 2])) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
56 %!assert (ishermitian ([])) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
57 %!assert (ishermitian ([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 (! ishermitian ("test")) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
59 %!assert (ishermitian ([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 (ishermitian ([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 (! ishermitian ("t")) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
62 %!assert (! ishermitian (["te"; "et"])) |
9869
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
63 |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
64 %!test |
ecd750d1eabd
move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
65 %! 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
|
66 %! assert (! ishermitian (s)); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
67 |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
68 %!error ishermitian ([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
|
69 %!error ishermitian () |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
70 |