UnitaryMatrixQ
Details and Options
- A p×q matrix m is unitary if p≥q and ConjugateTranspose[m].m is the q×q identity matrix, or p≤q and m.ConjugateTranspose[m] is the p×p identity matrix.
- UnitaryMatrixQ works for symbolic as well as numerical matrices.
- The following options can be given:
-
Normalized True test if matrix columns are normalized 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 aij and bij are taken to be equal if f[aij,bij] gives True.
- For approximate matrices, the option Tolerance->t can be used to indicate that the norm γ=m.m-In∞ satisfying γ≤t is taken to be zero where In is the identity matrix.
Examples
open all close allBasic Examples (2)
Test if a 2×2 numerical matrix is unitary:
UnitaryMatrixQ[(1/Sqrt[2])(| | |
| - | - |
| 1 | I |
| I | 1 |)]Test if a 3×3 symbolic matrix is explicitly unitary:
m = (| | | |
| ----- | ---------------------------------- | ----------------------------------- |
| 1 | 0 | 0 |
| 0 | (Cosh[Im[α]]/Sqrt[Cosh[2 Im[α]]]) | I (Sinh[Im[α]]/Sqrt[Cosh[2 Im[α]]]) |
| 0 | I(Sinh[Im[α]]/Sqrt[Cosh[2 Im[α]]]) | (Cosh[Im[α]]/Sqrt[Cosh[2 Im[α]]]) |);UnitaryMatrixQ[m]ConjugateTranspose[m].m == IdentityMatrix[3]//SimplifyScope (14)
Basic Uses (6)
Test if a real matrix is unitary:
m = (1/Sqrt[5]){{1, 2}, {-2, 1}};UnitaryMatrixQ[m]A real unitary matrix is also orthogonal:
OrthogonalMatrixQ[m]Test if a complex matrix is unitary:
m = (1/Sqrt[5]){{2, I}, {I, 2}};UnitaryMatrixQ[m]Test if an exact matrix is unitary:
m = (| | | |
| - | -- | -- |
| 4 | -5 | 2 |
| 3 | -3 | -3 |
| 5 | 5 | 5 |);UnitaryMatrixQ[m]UnitaryMatrixQ[Orthogonalize[m]]Use UnitaryMatrixQ with an arbitrary-precision matrix:
m = RandomReal[5, {3, 3}, WorkingPrecision -> 15]A random matrix is typically not unitary:
UnitaryMatrixQ[m]Use UnitaryMatrixQ with a symbolic matrix:
UnitaryMatrixQ[{{a, b}, {c, d}} / Sqrt[Abs[a]^2 + Abs[b]^2]]The matrix becomes unitary when
and
:
Block[{c = Conjugate[b], d = -Conjugate[a]}, UnitaryMatrixQ[{{a, b}, {c, d}} / Sqrt[Abs[a]^2 + Abs[b]^2], SameTest -> (FullSimplify[#1 - #2] == 0&)]]UnitaryMatrixQ works efficiently with large numerical matrices:
m = RandomReal[1, {1000, 1000}];AbsoluteTiming[UnitaryMatrixQ[m]]a = Orthogonalize[m];
AbsoluteTiming[UnitaryMatrixQ[a]]Special Matrices (4)
Use UnitaryMatrixQ with sparse matrices:
SparseArray[{Band[{1, 1}] -> -I}, {5, 5}]UnitaryMatrixQ[%]Use UnitaryMatrixQ with structured matrices:
SymmetrizedArray[{{1, 1} -> (1 + I/2), {1, 2} -> (1 - I/2), {2, 2} -> (1 + I/2)}, {2, 2}, Symmetric[All]]UnitaryMatrixQ[%]The identity matrix is unitary:
UnitaryMatrixQ[IdentityMatrix[3]]HilbertMatrix is not unitary:
UnitaryMatrixQ[HilbertMatrix[5]]Rectangular Semi-unitary Matrices (4)
Test if a rectangular matrix is semi-unitary:
m = (1/2)(| | | | |
| -- | - | - | -- |
| 1 | 1 | 1 | -1 |
| -I | I | I | I |);UnitaryMatrixQ[m]As there are more columns than rows, this indicates that the rows are orthonormal:
m.ConjugateTranspose[m]The columns are not orthonormal:
ConjugateTranspose[m].mTest a matrix with more rows than columns:
m = (1/2)(| | |
| ------- | --------- |
| 1 | 0 |
| 0 | ISqrt[2] |
| 0 | -ISqrt[2] |
| Sqrt[3] | 0 |);UnitaryMatrixQ[m]The columns of the matrix are orthonormal:
ConjugateTranspose[m].mm.ConjugateTranspose[m]Generate a random unitary matrix:
m = RandomVariate[CircularUnitaryMatrixDistribution[4]];UnitaryMatrixQ[m]Any subset of its rows forms a rectangular semi-unitary matrix:
UnitaryMatrixQ[m[[RandomSample[Range[4], 2]]]]As does any subset of its columns:
UnitaryMatrixQ[m[[All, RandomSample[Range[4], 2]]]]Rectangular identity matrices are semi-unitary:
UnitaryMatrixQ[IdentityMatrix[{3, 4}]]Options (4)
Normalized (2)
Symbolic unitary matrix columns are often not normalized to 1:
m = {{a, b}, {Conjugate[b], -Conjugate[a]}};
UnitaryMatrixQ[m]Avoid testing if the columns are normalized:
UnitaryMatrixQ[m, Normalized -> False]Multiply the second column of a unitary matrix by 2:
m = MapAt[2#&, RotationMatrix[π / 4, {1, 0, 1}], {All, 2}]UnitaryMatrixQ with NormalizedFalse will still give True for m:
UnitaryMatrixQ[m, Normalized -> False]However, it will not give true for ConjugateTranspose[m]:
UnitaryMatrixQ[ConjugateTranspose[m], Normalized -> False]This is because
is a diagonal matrix, but
is not:
MatrixForm /@ {m.m, m.m}//FullSimplifySameTest (1)
This matrix is unitary for a positive real
, but UnitaryMatrixQ gives False:
m = {{1, Exp[x I]}, {Cos[x] - I Sin[x], -1}} / Sqrt[2];UnitaryMatrixQ[m]Use the option SameTest to get the correct answer:
UnitaryMatrixQ[m, SameTest -> (Simplify[#1 - #2, x > 0] == 0&)]Tolerance (1)
Generate an orthogonal real-valued matrix with some random perturbation of order 10-14:
n = 3;
q = Orthogonalize[RandomVariate[NormalDistribution[], {n, n}] + I RandomVariate[NormalDistribution[], {n, n}]] + 10 ^ -13 * RandomReal[1, {n, n}];UnitaryMatrixQ[q]q.q is not exactly zero outside the main diagonal:
q.q^//MatrixFormAdjust the option Tolerance for accepting the matrix as unitary:
UnitaryMatrixQ[q, Tolerance -> 10 ^ -12]Tolerance is applied to the following value:
Norm[q.q^ - IdentityMatrix[3], Infinity]Applications (9)
Sources of Unitary Matrices (4)
Any orthonormal basis for
forms a unitary matrix:
Subscript[e, 1] = {(1/Sqrt[2]), (I/Sqrt[2]), 0};Subscript[e, 2] = {(1/Sqrt[2]), -(I/Sqrt[2]), 0};Subscript[e, 3] = {0, 0, Exp[(I π/3)]};Table[Subscript[e, i].Subscript[e, j], {i, 3}, {j, 3}]Putting the basis vectors in rows of a matrix forms a unitary matrix:
UnitaryMatrixQ[{Subscript[e, 1], Subscript[e, 2], Subscript[e, 3]}]Putting them in columns also gives a unitary matrix:
UnitaryMatrixQ[{Subscript[e, 1], Subscript[e, 2], Subscript[e, 3]}]Orthogonalize applied to linearly independent, complex vectors generates a unitary matrix:
m = Orthogonalize[RandomComplex[1. + I, {5, 5}]];UnitaryMatrixQ[m]The matrix does not need to be square, in which case the resulting matrix is semi-unitary:
m = Orthogonalize[RandomComplex[1. + I, {5, 3}]];UnitaryMatrixQ[m]m = Orthogonalize[RandomComplex[1. + I, {3, 5}]];UnitaryMatrixQ[m]But the starting matrix must have full rank:
m = (| | |
| - | - |
| 1 | I |
| 1 | I |);MatrixRank[m]UnitaryMatrixQ[Orthogonalize[m]]Any permutation matrix is unitary:
m = IdentityMatrix[4][[{2, 4, 1, 3}]]UnitaryMatrixQ[m]Matrices drawn from CircularUnitaryMatrixDistribution are unitary:
UnitaryMatrixQ /@ RandomVariate[CircularUnitaryMatrixDistribution[3], 10]So are matrices drawn from CircularOrthogonalMatrixDistribution:
UnitaryMatrixQ /@ RandomVariate[CircularOrthogonalMatrixDistribution[3], 10]As are matrices from CircularSymplecticMatrixDistribution:
UnitaryMatrixQ /@ RandomVariate[CircularSymplecticMatrixDistribution[3], 10]Uses of Unitary Matrices (5)
Unitary matrices preserve the standard inner product on
. In other words, if
is unitary and
and
are vectors, then
:
u = RandomVariate[CircularUnitaryMatrixDistribution[3], WorkingPrecision -> 16];
{v, w} = RandomComplex[1, {2, 3}, WorkingPrecision -> 16];UnitaryMatrixQ[u] && v.w == (u.v).(u.w)This means the angles between the vectors are unchanged:
VectorAngle[v, w] == VectorAngle[u.v, u.w]Since the norm is derived from the inner product, norms are preserved as well:
Norm[v] == Norm[u.v]Norm[w] == Norm[u.w]Unitary matrices play an important role in many matrix decompositions:
m = RandomComplex[{-1. - I, 1. + I}, {50, 50}];
{q, r} = QRDecomposition[m];
UnitaryMatrixQ[q]{u, w, v} = SingularValueDecomposition[m];
{UnitaryMatrixQ[u], UnitaryMatrixQ[v]}{s, t} = SchurDecomposition[m];
UnitaryMatrixQ[s]{p, h} = HessenbergDecomposition[m];
UnitaryMatrixQ[p]The matrix
is always unitary for any nonzero vector
:
n = 5;
Subscript[ℋ, v_] := IdentityMatrix[n] - 2 vv / v.v;
v = RandomComplex[1. + I, n];
UnitaryMatrixQ[Subscript[ℋ, v]]
is called a Householder reflection; as a pure reflection, its determinant is
:
Det[Subscript[ℋ, v]]//ChopIt represents a reflection through a plane perpendicular to
, sending
to
:
Subscript[ℋ, v].v == -vAny vector perpendicular to
is unchanged by
:
perp = Block[{w = RandomComplex[1 + n, n]}, w - Projection[w, v]];
Subscript[ℋ, v].perp == perpIn matrix computations,
is used to set to zero selected components of a given column vector
:
x = RandomComplex[1. + I, n];v = x - x[[1]] / Abs[x[[1]]] Norm[x]UnitVector[n, 1];
Subscript[ℋ, v].{x}//ChopIn quantum mechanics, time evolution is represented by a 1-parameter family of unitary matrices
.
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:
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[ℋ]The exponential MatrixExp[v] of an antihermitian matrix
is unitary. Define a matrix function through its differential equation
with initial value
and show that the solution is unitary:
AntihermitianMatrixQ[v = (| | | |
| ------- | ----- | ------ |
| 2I | -0.5I | 1. - I |
| -0.5I | 0 | 1. |
| -1. - I | -1. | -I |)]Solve and check that the resulting matrix is unitary at each time:
mm = NDSolveValue[{m'[t] == v.m[t], m[0] == IdentityMatrix[3]}, m, {t, 0., 5.}]With default settings, you get approximately unitary matrices:
Table[UnitaryMatrixQ[mm[t], Tolerance -> 10 ^ -5], {t, 0., 5., 1.}]The matrix 2-norm of the solution is 1:
Table[Norm@mm[t], {t, 0., 5., 1.}]rows = Table[ParametricPlot3D[Abs[mm[t][[i]]], {t, 0., 5.}, PlotStyle -> ColorData[97, i]], {i, 3}]//Quiet;Each row lies on the unit sphere:
Show[Graphics3D[{Opacity[0.5], Sphere[]}], rows]Properties & Relations (14)
A matrix is unitary if m.ConjugateTranspose[m]IdentityMatrix[n]:
m = (1/Sqrt[2]){{1, 1}, {I, -I}};{UnitaryMatrixQ[m], m.m^}For an approximate matrix, the identity is approximately true:
m = Orthogonalize[RandomComplex[1 + I, {3, 3}]];m.m^ - IdentityMatrix[3]//NormThe inverse of a unitary matrix is its conjugate transpose:
u = RandomVariate[CircularUnitaryMatrixDistribution[3]];Inverse[u] == ConjugateTranspose[u]Thus, the inverse, transpose, conjugate and conjugate transpose are all unitary matrices as well:
Table[UnitaryMatrixQ[f[u]], {f, {Inverse, Transpose, Conjugate, ConjugateTranspose}}]A unitary matrix preserves the standard inner product of vectors in
:
u = RandomVariate[CircularOrthogonalMatrixDistribution[4]];
{v, w} = RandomComplex[1 + I, {2, 4}];
UnitaryMatrixQ[u] && v.w == (u.v).(u.w)As a consequence, unitary matrices preserve norms as well:
Norm[v] == Norm[u.v]Norm[w] == Norm[u.w]Any real-valued orthogonal matrix is unitary:
m = Orthogonalize[RandomReal[1, {3, 3}]];{OrthogonalMatrixQ[m], UnitaryMatrixQ[m]}But a complex unitary matrix is typically not orthogonal:
m = Orthogonalize[RandomComplex[1 + I, {3, 3}]];{OrthogonalMatrixQ[m], UnitaryMatrixQ[m]}Products of unitary matrices are unitary:
{m1, m2} = RandomVariate[CircularOrthogonalMatrixDistribution[3], 2];
{UnitaryMatrixQ[m1], UnitaryMatrixQ[m2]}UnitaryMatrixQ[m1.m2]m = Orthogonalize[RandomComplex[1 + I, {3, 3}]];{UnitaryMatrixQ[m], NormalMatrixQ[m]}Unitary matrices have eigenvalues that lie on the unit circle:
m = RandomVariate[CircularUnitaryMatrixDistribution[3]];UnitaryMatrixQ[m]Use Eigenvalues to find eigenvalues:
Eigenvalues[m]Verify they lie on the unit circle:
Abs[%]Unitary matrices have a complete set of eigenvectors:
m = RandomVariate[CircularSymplecticMatrixDistribution[2]];UnitaryMatrixQ[m]As a consequence, they must be diagonalizable:
DiagonalizableMatrixQ[m]Use Eigenvectors to find eigenvectors:
Eigenvectors[m]//ChopThe singular values are all 1 for a unitary matrix:
m = Orthogonalize[RandomComplex[1 + I, {3, 3}]];UnitaryMatrixQ[m]SingularValueList[m]The absolute value of the determinant of a unitary matrix is 1:
m = RandomVariate[CircularUnitaryMatrixDistribution[3]];{UnitaryMatrixQ[m], Abs[Det[m]]}The 2-norm of a unitary matrix is always 1:
m = Orthogonalize[RandomComplex[1 + I, {3, 3}]];{UnitaryMatrixQ[m], Norm[m]}Real powers of unitary matrices are unitary:
m = RandomVariate[CircularSymplecticMatrixDistribution[3]];UnitaryMatrixQ[m]UnitaryMatrixQ[MatrixPower[m, RandomReal[{-2, 2}]]]MatrixExp[I h] is unitary for any Hermitian matrix h:
h = Block[{a = RandomComplex[1 + I, {5, 5}]}, a + a^];HermitianMatrixQ[h]UnitaryMatrixQ[MatrixExp[I h]]UnitaryMatrix can be used to explicitly construct unitary matrices:
UnitaryMatrix[RandomVariate[CircularUnitaryMatrixDistribution[3]]]These satisfy UnitaryMatrixQ:
UnitaryMatrixQ[%]Related Guides
History
Text
Wolfram Research (2014), UnitaryMatrixQ, Wolfram Language function, https://reference.wolfram.com/language/ref/UnitaryMatrixQ.html.
CMS
Wolfram Language. 2014. "UnitaryMatrixQ." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/UnitaryMatrixQ.html.
APA
Wolfram Language. (2014). UnitaryMatrixQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/UnitaryMatrixQ.html
BibTeX
@misc{reference.wolfram_2026_unitarymatrixq, author="Wolfram Research", title="{UnitaryMatrixQ}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/UnitaryMatrixQ.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_unitarymatrixq, organization={Wolfram Research}, title={UnitaryMatrixQ}, year={2014}, url={https://reference.wolfram.com/language/ref/UnitaryMatrixQ.html}, note=[Accessed: 13-June-2026]}