annotate scripts/linear-algebra/ishermitian.m @ 26376:00f796120a6d stable

maint: Update copyright dates in all source files.
author John W. Eaton <jwe@octave.org>
date Wed, 02 Jan 2019 16:32:43 -0500
parents 0d755097d73f
children c0fa4a9eef95
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26376
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 26289
diff changeset
1 ## Copyright (C) 1996-2019 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 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
6 ## Octave is free software: you can redistribute it and/or modify it
9869
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
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
8 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
9 ## (at your option) any later version.
9869
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
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
14 ## GNU General Public License for more details.
9869
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
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
18 ## <https://www.gnu.org/licenses/>.
9869
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 -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20160
diff changeset
21 ## @deftypefn {} {} ishermitian (@var{A})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20160
diff changeset
22 ## @deftypefnx {} {} ishermitian (@var{A}, @var{tol})
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
23 ## @deftypefnx {} {} ishermitian (@var{A}, @qcode{"skew"})
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
24 ## @deftypefnx {} {} ishermitian (@var{A}, @qcode{"skew"}, @var{tol})
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
25 ## Return true if @var{A} is a Hermitian or skew-Hermitian matrix within the
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
26 ## tolerance specified by @var{tol}.
18921
d0d0858cfab1 doc: Match docstring variable names to function variable names for linear-algebra m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
27 ##
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
28 ## The default tolerance is zero (uses faster code).
20160
03b9d17a2d95 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
29 ##
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
30 ## The type of symmetry to check may be specified with the additional input
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
31 ## @qcode{"nonskew"} (default) for regular Hermitian or @qcode{"skew"} for
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
32 ## skew-Hermitian.
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
33 ##
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
34 ## Background: A matrix is Hermitian if the complex conjugate transpose of the
25228
581d3a13d7e2 ishermitian.m, issymmetric.m: Use @tcode macro in docstring (bug #53556).
Rik <rik@octave.org>
parents: 25227
diff changeset
35 ## matrix is equal to the original matrix: @w{@tcode{@var{A} == @var{A}'}}. If
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
36 ## a tolerance is given then the calculation is
18921
d0d0858cfab1 doc: Match docstring variable names to function variable names for linear-algebra m-files.
Rik <rik@octave.org>
parents: 17744
diff changeset
37 ## @code{norm (@var{A} - @var{A}', Inf) / norm (@var{A}, Inf) < @var{tol}}.
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
38 ##
26043
5cef57130cb9 doc: grammar check m-files in scripts/ directory.
Rik <rik@octave.org>
parents: 25228
diff changeset
39 ## A matrix is skew-Hermitian if the complex conjugate transpose of the matrix
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
40 ## is equal to the negative of the original matrix:
25228
581d3a13d7e2 ishermitian.m, issymmetric.m: Use @tcode macro in docstring (bug #53556).
Rik <rik@octave.org>
parents: 25227
diff changeset
41 ## @w{@tcode{@var{A} == -@var{A}'}}. If a
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
42 ## tolerance is given then the calculation is
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
43 ## @code{norm (@var{A} + @var{A}', Inf) / norm (@var{A}, Inf) < @var{tol}}.
11431
0d9640d755b1 Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
44 ## @seealso{issymmetric, isdefinite}
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
45 ## @end deftypefn
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
46
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
47 ## 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
48 ## Created: August 1993
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
49 ## Adapted-By: jwe
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
50
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
51 function retval = ishermitian (A, skewopt = "nonskew", tol = 0)
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
52
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
53 if (nargin < 1 || nargin > 3)
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
54 print_usage ();
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
55 endif
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
56
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
57 if (nargin == 2)
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
58 ## Decode whether second argument is skewopt or tol
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
59 if (isnumeric (skewopt))
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
60 tol = skewopt;
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
61 skewopt = "nonskew";
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
62 elseif (! ischar (skewopt))
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
63 error ("ishermitian: second argument must be a non-negative scalar TOL, or one of the strings: 'skew' / 'nonskew'");
25227
a937ffe7dfd9 fix typo in previous change
John W. Eaton <jwe@octave.org>
parents: 25225
diff changeset
64 endif
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
65 endif
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
66
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
67 ## Validate inputs
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
68 retval = (isnumeric (A) || islogical (A)) && issquare (A);
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
69 if (! retval)
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
70 return;
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
71 endif
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
72
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
73 if (! (strcmp (skewopt, "skew") || strcmp (skewopt, "nonskew")))
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
74 error ("ishermitian: SKEWOPT must be 'skew' or 'nonskew'");
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
75 endif
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
76
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
77 if (! (isnumeric (tol) && isscalar (tol) && tol >= 0))
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
78 error ("ishermitian: TOL must be a scalar >= 0");
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
79 endif
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
80
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
81 ## Calculate Hermitian-ness
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
82 if (strcmp (skewopt, "nonskew"))
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
83 if (tol == 0)
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
84 ## check for exact symmetry
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
85 retval = ! any ((A != A')(:));
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
86 else
26289
0d755097d73f issymetric.m, ishermitian.m: Don't error on logical matrices (bug #42487).
Rik <rik@octave.org>
parents: 26043
diff changeset
87 if (islogical (A))
0d755097d73f issymetric.m, ishermitian.m: Don't error on logical matrices (bug #42487).
Rik <rik@octave.org>
parents: 26043
diff changeset
88 ## Hack to allow norm to work. Choose single to minimize memory.
0d755097d73f issymetric.m, ishermitian.m: Don't error on logical matrices (bug #42487).
Rik <rik@octave.org>
parents: 26043
diff changeset
89 A = single (A);
0d755097d73f issymetric.m, ishermitian.m: Don't error on logical matrices (bug #42487).
Rik <rik@octave.org>
parents: 26043
diff changeset
90 endif
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
91 norm_x = norm (A, Inf);
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
92 retval = norm_x == 0 || norm (A - A', Inf) / norm_x <= tol;
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
93 endif
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
94 else
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
95 ## skew-Hermitian
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
96 if (tol == 0)
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
97 retval = ! any ((A != -A')(:));
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
98 else
26289
0d755097d73f issymetric.m, ishermitian.m: Don't error on logical matrices (bug #42487).
Rik <rik@octave.org>
parents: 26043
diff changeset
99 if (islogical (A))
0d755097d73f issymetric.m, ishermitian.m: Don't error on logical matrices (bug #42487).
Rik <rik@octave.org>
parents: 26043
diff changeset
100 ## Hack to allow norm to work. Choose single to minimize memory.
0d755097d73f issymetric.m, ishermitian.m: Don't error on logical matrices (bug #42487).
Rik <rik@octave.org>
parents: 26043
diff changeset
101 A = single (A);
0d755097d73f issymetric.m, ishermitian.m: Don't error on logical matrices (bug #42487).
Rik <rik@octave.org>
parents: 26043
diff changeset
102 endif
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
103 norm_x = norm (A, Inf);
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
104 retval = norm_x == 0 || norm (A + A', Inf) / norm_x <= tol;
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
105 endif
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
106 endif
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
107
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
108 endfunction
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
109
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
110
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
111 %!assert (ishermitian (1))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
112 %!assert (! ishermitian ([1, 2]))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
113 %!assert (ishermitian ([]))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
114 %!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
115 %!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
116 %!assert (ishermitian ([1, -2i; 2i, 1]))
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
117 %!assert (ishermitian (speye (100)))
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
118 %!assert (ishermitian (logical (eye (2))))
26289
0d755097d73f issymetric.m, ishermitian.m: Don't error on logical matrices (bug #42487).
Rik <rik@octave.org>
parents: 26043
diff changeset
119 %!assert (! ishermitian (logical ([1 1; 0 1])))
0d755097d73f issymetric.m, ishermitian.m: Don't error on logical matrices (bug #42487).
Rik <rik@octave.org>
parents: 26043
diff changeset
120 %!assert (ishermitian (logical ([1 1; 0 1]), 0.5))
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
121 %!assert (ishermitian ([0, 2i; 2i, 0], "skew"))
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
122 %!assert (! ishermitian ([0, 2; -2, eps], "skew"))
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
123 %!assert (ishermitian ([0, 2; -2, eps], "skew", eps))
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
124
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
125 %!assert (! (ishermitian ("test")))
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
126 %!assert (! (ishermitian ("t")))
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
127 %!assert (! (ishermitian (["te"; "et"])))
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
128 %!assert (! ishermitian ({1}))
9869
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
129 %!test
ecd750d1eabd move issymmetric & isdefinite to linear-algebra, create ishermitian
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
130 %! 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
131 %! assert (! ishermitian (s));
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
132
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
133 ## Test input validation
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
134 %!error ishermitian ()
25225
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
135 %!error ishermitian (1,2,3,4)
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
136 %!error <second argument must be> ishermitian (1, {"skew"})
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
137 %!error <SKEWOPT must be 'skew' or 'nonskew'> ishermitian (1, "foobar")
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
138 %!error <SKEWOPT must be 'skew' or 'nonskew'> ishermitian (1, "foobar")
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
139 %!error <TOL must be a scalar .= 0> ishermitian (1, "skew", {1})
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
140 %!error <TOL must be a scalar .= 0> ishermitian (1, "skew", [1 1])
114ad8f22ee6 ishermitian.m; Overhaul function and expand to check skew-symmetry (bug #53556).
Rik <rik@octave.org>
parents: 25054
diff changeset
141 %!error <TOL must be a scalar .= 0> ishermitian (1, -1)