HermitianMatrixQ
Details and Options
- HermitianMatrixQ is also known as a self-adjoint.
- A matrix m is Hermitian if m==ConjugateTranspose[m].
- HermitianMatrixQ works for symbolic as well as numerical matrices.
- The following options can be given:
-
SameTest Automatic function to test equality of expressions Tolerance Automatic tolerance for approximate numbers - For exact and symbolic matrices, the option SameTest->f indicates that two entries mij and mkl are taken to be equal if f[mij,mkl] gives True.
- For approximate matrices, the option Tolerance->t can be used to indicate that all entries Abs[mij]≤t are taken to be zero.
- For matrix entries Abs[mij]>t, equality comparison is done except for the last
bits, where
is $MachineEpsilon for MachinePrecision matrices and
for matrices of Precision
.
Examples
open all close allBasic Examples (2)
Test if a 2×2 numeric matrix is explicitly Hermitian:
HermitianMatrixQ[(| | |
| ------- | ------- |
| 1 | 3 + 4 I |
| 3 - 4 I | 2 |)]Test if a 3×3 symbolic matrix is explicitly Hermitian:
HermitianMatrixQ[(| | | |
| -- | -- | -- |
| 0 | a | b |
| a | 1 | c |
| b | c | -1 |)]Scope (10)
Basic Uses (6)
Test if a real machine-precision matrix is Hermitian:
m = {{1, 2.3}, {2.3, 4}};HermitianMatrixQ[m]A real Hermitian matrix is also symmetric:
SymmetricMatrixQ[m]Test if a complex matrix is Hermitian:
m = {{1, 2 - 3I}, {2 + 3I, 4}};HermitianMatrixQ[m]A complex Hermitian matrix has symmetric real part and antisymmetric imaginary part:
{SymmetricMatrixQ[Re[m]], AntisymmetricMatrixQ[Im[m]]}Test if an exact matrix is Hermitian:
m = (| | | |
| - | -- | -- |
| 4 | -5 | 2 |
| 3 | -3 | -3 |
| 5 | 5 | 5 |);HermitianMatrixQ[m]HermitianMatrixQ[(m + m^/2)]Use HermitianMatrixQ with an arbitrary-precision matrix:
m = RandomReal[5, {3, 3}, WorkingPrecision -> 15]A random matrix is typically not Hermitian:
HermitianMatrixQ[m]Use HermitianMatrixQ with a symbolic matrix:
HermitianMatrixQ[{{a, b}, {c, d}}]The matrix becomes Hermitian when
and diagonal entries are explicitly real-valued:
Block[{c = b^, a = Re[e], d = Im[f]}, HermitianMatrixQ[{{a, b}, {c, d}}]]HermitianMatrixQ works efficiently with large numerical matrices:
m = RandomReal[1, {1000, 1000}];AbsoluteTiming[HermitianMatrixQ[m]]a = m + m^;
AbsoluteTiming[HermitianMatrixQ[a]]Special Matrices (4)
Use HermitianMatrixQ with sparse matrices:
SparseArray[{i_, j_} -> i + j + (i - j)I, {5, 5}]HermitianMatrixQ[%]Use HermitianMatrixQ with structured matrices:
SymmetrizedArray[{{1, 2} -> 4 + I, {3, 2} -> 5}, {3, 3}, Hermitian[All]]HermitianMatrixQ[%]Use with a QuantityArray structured matrix:
QuantityArray[{{1, 2}, {3, 4}}, "Meters"]HermitianMatrixQ[%]The identity matrix is Hermitian:
HermitianMatrixQ[IdentityMatrix[3]]HilbertMatrix is Hermitian:
HermitianMatrixQ[HilbertMatrix[5]]Options (2)
SameTest (1)
This matrix is Hermitian for a positive real
, but HermitianMatrixQ gives False:
m = {{1, Exp[Log[I x]]}, {-I x, 2}};HermitianMatrixQ[m]Use the option SameTest to get the correct answer:
HermitianMatrixQ[m, SameTest -> (Simplify[#1 - #2, x > 0] == 0&)]Tolerance (1)
Generate a complex-valued Hermitian matrix with some random perturbation of order 10-14:
SeedRandom[12];
m = Block[{a = RandomComplex[1 + I, {3, 3}]}, a + a^];
m = m + 10^-14 RandomReal[10, {3, 3}];HermitianMatrixQ[m]Adjust the option Tolerance to accept this matrix as Hermitian:
HermitianMatrixQ[m, Tolerance -> 10 ^ -12]The norm of the difference between the matrix and its conjugate transpose:
m - m^//NormApplications (8)
Sources of Hermitian Matrices (5)
A matrix generated from a Hermitian function
is Hermitian:
f[x_, y_] := Re[x]Re[y]Conjugate[f[y, x]] == f[x, y]//SimplifyBy using Table, it generates a Hermitian matrix:
HermitianMatrixQ[Table[f[i, j], {i, 5}, {j, 5}]]SymmetrizedArray can generate matrices (and general arrays) with symmetries:
SymmetrizedArray[{{1, 2} -> a, {2, 3} -> b}, {3, 3}, Hermitian[{1, 2}]]HermitianMatrixQ[%]Convert back to an ordinary matrix using Normal:
Normal[SymmetrizedArray[StructuredArray`StructuredData[{3, 3}, {{{1, 2} -> a, {2, 3} -> b},
Hermitian[{1, 2}]}]]]The Pauli matrices are Hermitian:
HermitianMatrixQ /@ Table[PauliMatrix[k], {k, 3}]Several statistical measures of complex data are Hermitian matrices, including Covariance:
data = RandomComplex[1 + I, {2, 5}];HermitianMatrixQ[Covariance[data]]HermitianMatrixQ[Correlation[data]]HermitianMatrixQ[AbsoluteCorrelation[data]]Matrices drawn from GaussianUnitaryMatrixDistribution are Hermitian:
HermitianMatrixQ /@ RandomVariate[GaussianUnitaryMatrixDistribution[3], 10]Matrices drawn from GaussianSymplecticMatrixDistribution are Hermitian:
HermitianMatrixQ /@ RandomVariate[GaussianSymplecticMatrixDistribution[2], 10]Uses of Hermitian Matrices (3)
A positive-definite, Hermitian matrix or metric
defines an inner product by
:
(g = {{7, 2 + I, 3I}, {2 - I, 6, -2}, {-3I, -2, 5}})//MatrixFormip[u_, v_] := Conjugate[u].g.vVerify that
is in fact Hermitian and positive definite:
HermitianMatrixQ[g] && PositiveDefiniteMatrixQ[g]Orthogonalize the standard basis of
to find an orthonormal basis:
{Subscript[e, 1], Subscript[e, 2], Subscript[e, 3]} = Orthogonalize[IdentityMatrix[3], ip]Confirm that this basis is orthonormal with respect to the inner product
:
Table[ip[Subscript[e, i], Subscript[e, j]], {i, 3}, {j, 3}]//SimplifyIn quantum mechanics, time evolution is represented by a 1-parameter family of unitary matrices
. The
times the logarithmic derivative of
is a Hermitian matrix called the Hamiltonian or energy operator
. Its eigenvalues represent the possible energies of the system. For the following time evolution, compute the Hamiltonian and possible energies:
u[t_] := (| | | |
| ------------------------ | ---------------------- | ------------------------ |
| (1/2) + (1/2) Cos[t ω0] | -(I Sin[t ω0]/Sqrt[2]) | -(1/2) + (1/2) Cos[t ω0] |
| -(I Sin[t ω0]/Sqrt[2]) | Cos[t ω0] | -(I Sin[t ω0]/Sqrt[2]) |
| -(1/2) + (1/2) Cos[t ω0] | -(I Sin[t ω0]/Sqrt[2]) | (1/2) + (1/2) Cos[t ω0] |)First, verify the matrices are, in fact, unitary under the assumptions that
and
are real:
UnitaryMatrixQ[u[t], SameTest -> (Simplify[#1 - #2 == 0, {t, Subscript[ω, 0]}∈Reals] &)]Compute the logarithmic derivative:
u'[t].Inverse[u[t]]//FullSimplifyAntihermitianMatrixQ[%, SameTest -> (Simplify[#1 - #2 == 0, {Subscript[ω, 0]}∈Reals] &)]MatrixForm[ℋ = I ℏ %%]Verify that the matrix is Hermitian:
HermitianMatrixQ[ℋ, SameTest -> (Simplify[#1 - #2 == 0, {ℏ, Subscript[ω, 0]}∈Reals] &)]Its real eigenvalues represent the possible energies:
Eigenvalues[ℋ]Use a different method for Hermitian matrices, with failover to a general method:
myLS[m_, b_] := Module[{x},
If[HermitianMatrixQ[m],
(* "Cholesky" works for positive definite matrices only *)
Quiet[x = LinearSolve[m, b, Method -> "Cholesky"]]];
If[!VectorQ[x], x = LinearSolve[m, b]];
x]Construct complex-valued matrices for testing:
SeedRandom[759];
n = 1000;
m = RandomComplex[1 + 2I, {n, n}];
mh = m + ConjugateTranspose[m]; (* Hermitian part *)
mpd = m.ConjugateTranspose[m]; (* positive definite *)
b = N[Range[n]];For the non-Hermitian matrix m, the function myLS just uses Gaussian elimination:
Timing[myLS[m, b];]For the Hermitian indefinite matrix mh, try Cholesky and continue with Gaussian elimination:
HermitianMatrixQ[mh]Timing[myLS[mh, b];]For the Hermitian positive definite matrix mpd, try Cholesky, which succeeds:
{HermitianMatrixQ[mpd], PositiveDefiniteMatrixQ[mpd]}Timing[myLS[mpd, b];]Properties & Relations (16)
HermitianMatrixQ[x] trivially returns False for any x that is not a matrix:
HermitianMatrixQ[Sqrt[3]]A matrix is Hermitian if m==ConjugateTranspose[m]:
m = (| | |
| ------- | ------- |
| 1 | 2 + 2 I |
| 2 - 2 I | 3 |);{m == ConjugateTranspose[m], HermitianMatrixQ[m]}A Hermitian matrix must have real diagonal elements:
m = (| | |
| ------- | ------- |
| 1 | 2 + 2 I |
| 2 - 2 I | 3 |);HermitianMatrixQ[m]Use Diagonal to pick out the diagonal elements:
Diagonal[m]A real-valued symmetric matrix is Hermitian:
m = (| | |
| - | - |
| 1 | 2 |
| 2 | 3 |);{SymmetricMatrixQ[m], HermitianMatrixQ[m]}But a complex-valued symmetric matrix may not be:
m = (| | |
| ------- | ------- |
| 1 + I | 2 + 2 I |
| 2 + 2 I | 3 + 3 I |);{SymmetricMatrixQ[m], HermitianMatrixQ[m]}Use Symmetrize with the symmetry Hermitian to compute the Hermitian part of a matrix:
m = RandomComplex[1 + I, {3, 3}];Symmetrize[m, Hermitian[{1, 2}]]This equals mean of m and ConjugateTranspose[m]:
% == (m + m/2)Any matrix can be represented as the sum of its Hermitian and antihermitian parts:
m = RandomComplex[1 + I, {3, 3}];
{h, ah} = {(m + m) / 2, (m - m) / 2};m == h + ahUse AntihermitianMatrixQ to test whether a matrix is antihermitian:
{HermitianMatrixQ[h], AntihermitianMatrixQ[ah]}If
is a Hermitian matrix, then
is antihermitian:
m = Block[{a = RandomComplex[1 + I, {5, 5}]}, a + a^];{HermitianMatrixQ[m], AntihermitianMatrixQ[I m]}MatrixExp[I h] is unitary for any Hermitian matrix h:
m = Block[{a = RandomComplex[1 + I, {5, 5}]}, a + a^];UnitaryMatrixQ[MatrixExp[I m]]A Hermitian matrix is always a normal matrix:
m = Block[{a = RandomReal[1, {10, 10}]}, a + a];Use NormalMatrixQ to test whether a matrix is normal:
{HermitianMatrixQ[m], NormalMatrixQ[m]}Hermitian matrices have all real eigenvalues:
m = Block[{a = RandomReal[1, {5, 5}]}, a + a];HermitianMatrixQ[m]Use Eigenvalues to find eigenvalues:
Eigenvalues[m]CharacteristicPolynomial[m,x] for Hermitian m has real coefficients:
m = Block[{a = RandomComplex[1 + I, {4, 4}]}, a + a^];CharacteristicPolynomial[m, x]Moreover, it can be factored into linear terms:
Factor[%]Hermitian matrices have a complete set of eigenvectors:
m = Block[{a = RandomComplex[1 + I, {3, 3}]}, a + a];HermitianMatrixQ[m]As a consequence, they must be diagonalizable:
DiagonalizableMatrixQ[m]Use Eigenvectors to find eigenvectors:
Eigenvectors[m]Hermitian matrices have a real-valued determinant:
m = Block[{a = RandomComplex[1 + I, {3, 3}]}, a + a];HermitianMatrixQ[m]Use Det to compute the determinant:
Det[m]//ChopThe inverse of a Hermitian matrix is Hermitian:
m = Block[{a = RandomComplex[1 + I, {3, 3}]}, a + a];HermitianMatrixQ[Inverse[m]]Real-valued matrix functions of Hermitian matrices are Hermitian, including MatrixExp:
m = Block[{a = RandomComplex[1 + I, {3, 3}]}, a + a];HermitianMatrixQ[MatrixExp[m]]And any univariate analytic function representable using MatrixFunction:
HermitianMatrixQ[MatrixFunction[Sin, m]]Note that while integer matrix powers are Hermitian, noninteger powers are not:
{HermitianMatrixQ[MatrixPower[m, 9]], HermitianMatrixQ[MatrixPower[m, (1/2)]]}HermitianMatrix can be used to explicitly construct Hermitian matrices:
HermitianMatrix[RandomVariate[GaussianUnitaryMatrixDistribution[3]]]These satisfy HermitianMatrixQ:
HermitianMatrixQ[%]Possible Issues (2)
A complex symmetric matrix is not Hermitian:
m = {{1, 3 + 4 I}, {3 + 4 I, 5}};{SymmetricMatrixQ[m], HermitianMatrixQ[m]}HermitianMatrixQ[m] gives False if m is only Hermitian when the variables in it are real:
h = (| | | |
| -------- | ------- | ----- |
| x | x + I y | x y z |
| x - I y | y | y z |
| x y z | y z | z |);
HermitianMatrixQ[h]Use the SameTest options to declare the variables to be real:
HermitianMatrixQ[h, SameTest -> (Simplify[#1 == #2, {x, y, z}∈Reals]&)]Related Guides
Text
Wolfram Research (2007), HermitianMatrixQ, Wolfram Language function, https://reference.wolfram.com/language/ref/HermitianMatrixQ.html (updated 2014).
CMS
Wolfram Language. 2007. "HermitianMatrixQ." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2014. https://reference.wolfram.com/language/ref/HermitianMatrixQ.html.
APA
Wolfram Language. (2007). HermitianMatrixQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/HermitianMatrixQ.html
BibTeX
@misc{reference.wolfram_2026_hermitianmatrixq, author="Wolfram Research", title="{HermitianMatrixQ}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/HermitianMatrixQ.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_hermitianmatrixq, organization={Wolfram Research}, title={HermitianMatrixQ}, year={2014}, url={https://reference.wolfram.com/language/ref/HermitianMatrixQ.html}, note=[Accessed: 12-June-2026]}