SymmetricMatrixQ
Details and Options
- A matrix m is symmetric if m==Transpose[m].
- SymmetricMatrixQ 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)
Scope (10)
Basic Uses (6)
Test if a real machine-precision matrix is symmetric:
m = {{1, 2.3}, {2.3, 2}};SymmetricMatrixQ[m]A real symmetric matrix is also Hermitian:
HermitianMatrixQ[m]Test if a complex matrix is symmetric:
m = {{1 + I, 2 - 3I}, {2 - 3I, 2 - 3I}};SymmetricMatrixQ[m]A complex symmetric matrix has symmetric real and imaginary parts:
{SymmetricMatrixQ[Re[m]], SymmetricMatrixQ[Im[m]]}Test if an exact matrix is symmetric:
m = (| | | |
| - | -- | -- |
| 4 | -5 | 2 |
| 3 | -3 | -3 |
| 5 | 5 | 5 |);SymmetricMatrixQ[m]SymmetricMatrixQ[(m + m^/2)]Use SymmetricMatrixQ with an arbitrary-precision matrix:
m = RandomReal[5, {3, 3}, WorkingPrecision -> 15]A random matrix is typically not symmetric:
SymmetricMatrixQ[m]Use SymmetricMatrixQ with a symbolic matrix:
SymmetricMatrixQ[{{a, b}, {c, d}}]The matrix becomes symmetric when
:
Block[{c = b}, SymmetricMatrixQ[{{a, b}, {c, d}}]]SymmetricMatrixQ works efficiently with large numerical matrices:
m = RandomReal[1, {1000, 1000}];AbsoluteTiming[SymmetricMatrixQ[m]]a = m + m^;
AbsoluteTiming[SymmetricMatrixQ[a]]Special Matrices (4)
Use SymmetricMatrixQ with sparse matrices:
SparseArray[{i_, j_} -> (i - j)^2 / (i + j)^2, {5, 5}]SymmetricMatrixQ[%]Use SymmetricMatrixQ with structured matrices:
SymmetrizedArray[{{1, 2} -> a, {2, 3} -> b}, {3, 3}, Symmetric[{1, 2}]]SymmetricMatrixQ[%]Use with a QuantityArray structured matrix:
QuantityArray[{{1, 2}, {3, 4}}, "Meters"]SymmetricMatrixQ[%]The identity matrix is symmetric:
SymmetricMatrixQ[IdentityMatrix[5]]HilbertMatrix is symmetric:
SymmetricMatrixQ[HilbertMatrix[5]]Options (2)
SameTest (1)
This matrix is symmetric for a positive real
, but SymmetricMatrixQ gives False:
m = {{1, Log[x ^ 2]}, {2 Log[x], 2}};SymmetricMatrixQ[m]Use the option SameTest to get the correct answer:
SymmetricMatrixQ[m, SameTest -> (Simplify[#1 - #2, x > 0] == 0&)]Tolerance (1)
Generate a real-valued symmetric matrix with some random perturbation of order 10-14:
SeedRandom[123];
m = Block[{a = RandomReal[1, {3, 3}]}, a + a^];
m = m + 10^-14 RandomReal[10, {3, 3}];SymmetricMatrixQ[m]Adjust the option Tolerance to accept this matrix as symmetric:
SymmetricMatrixQ[m, Tolerance -> 10 ^ -12]The norm of the difference between the matrix and its transpose:
m - m^//NormApplications (13)
Generating Symmetric Matrices (4)
Any matrix generated from a symmetric function
is symmetric:
f[i_, j_] := i jf[i, j] == f[j, i]Using Table generates a symmetric matrix:
SymmetricMatrixQ[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}, Symmetric[{1, 2}]]SymmetricMatrixQ[%]Convert back to an ordinary matrix using Normal:
Normal[SymmetrizedArray[StructuredArray`StructuredData[{3, 3}, {{{1, 2} -> a, {2, 3} -> b},
Symmetric[{1, 2}]}]]]Check that matrices drawn from GaussianOrthogonalMatrixDistribution are symmetric:
SymmetricMatrixQ /@ RandomVariate[GaussianOrthogonalMatrixDistribution[3], 10]Matrices drawn from CircularOrthogonalMatrixDistribution are symmetric and unitary:
(mat |-> SymmetricMatrixQ[mat]∧UnitaryMatrixQ[mat] ) /@ RandomVariate[CircularOrthogonalMatrixDistribution[3], 10]Every Jordan matrix is similar to a symmetric matrix. Since any square matrix is similar to its Jordan form, this means that any square matrix is similar to a symmetric matrix. Define a function for generating an
Jordan block for eigenvalue
:
j[λ_, n_] := λ IdentityMatrix[n] + SparseArray[{Band[{1, 2}] -> 1}, {n, n}]For example, here is the Jordan matrix of dimension 4 for the eigenvalue
:
j[λ, 4]//MatrixFormDefine a function for generating a corresponding complex similarity transformation:
s[n_] := (1/Sqrt[2]) (IdentityMatrix[n] + SparseArray[{Band[{1, n}, {n, 1}, {1, -1}] -> I}, {n, n}])The matrix is a sum of
times the identity matrix and
times the backward identity matrix:
s[4]//MatrixFormThen
is symmetric, which shows that the Jordan matrix is similar to a symmetric matrix:
s[4].j[λ, 4].Inverse[s[4]]//Simplify//MatrixFormConfirm the matrix is symmetric:
SymmetricMatrixQ[%]Examples of Symmetric Matrices (5)
The Hessian matrix of a function is symmetric:
f[x_, y_] := Log[Cos[x] ^ 2 + Sin[y]];hessian = D[f[x, y], {{x, y}, 2}]SymmetricMatrixQ[hessian]Many special matrices are symmetric, including FourierMatrix:
SymmetricMatrixQ[FourierMatrix[2 ^ 7]]SymmetricMatrixQ[HadamardMatrix[2 ^ 7]]SymmetricMatrixQ[HankelMatrix[Range[100], Range[100, 1, -1]]]And HilbertMatrix:
SymmetricMatrixQ[HilbertMatrix[100]]Table[MatrixPlot[g, FrameTicks -> None], {g, {FourierMatrix[2 ^ 7], HadamardMatrix[2 ^ 7], HankelMatrix[Range[100], Range[100, 1, -1]], HilbertMatrix[100]}}]Many filter kernel matrices are symmetric, including DiskMatrix:
SymmetricMatrixQ[DiskMatrix[7]]SymmetricMatrixQ[CrossMatrix[1]]SymmetricMatrixQ[DiamondMatrix[10]]{ArrayPlot[DiskMatrix[7]], ArrayPlot[CrossMatrix[1]], ArrayPlot[DiamondMatrix[10]]}AdjacencyMatrix of an undirected graph is symmetric:
AdjacencyMatrix[[image]]SymmetricMatrixQ[%]As is KirchhoffMatrix:
KirchhoffMatrix[[image]]SymmetricMatrixQ[%]Visualize adjacency and Kirchhoff matrices for different graphs:
{Table[MatrixPlot[AdjacencyMatrix[g], FrameTicks -> None], {g, {CirculantGraph[12, {2, 4}], HypercubeGraph[6], PetersenGraph[10, 8]}}], Table[MatrixPlot[KirchhoffMatrix[g], FrameTicks -> None], {g, {CirculantGraph[12, {2, 4}], HypercubeGraph[6], PetersenGraph[10, 8]}}]}Several statistical measures are symmetric matrices, including Covariance:
data = RandomVariate[DirichletDistribution[Range[5]], 10^3];SymmetricMatrixQ[Covariance[data]]SymmetricMatrixQ[Correlation[data]]SymmetricMatrixQ[AbsoluteCorrelation[data]]Uses of Symmetric Matrices (4)
A positive-definite, real symmetric matrix or metric
defines an inner product by
:
(g = {{7, 2, 0}, {2, 6, -2}, {0, -2, 5}})//MatrixFormip[u_, v_] := u.g.vVerify that
is in fact symmetric and positive definite:
SymmetricMatrixQ[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}]//SimplifyThe moment of inertia tensor is the equivalent of mass for rotational motion. For example, kinetic energy is
, with
taking the place of the mass
and angular velocity
taking the place of linear velocity
in the formula
.
can be represented by a positive-definite symmetric matrix. Compute the moment of inertia for a tetrahedron with endpoints at the origin and positive coordinate axes:
MomentOfInertia[Tetrahedron[{{0, 0, 0}, {a, 0, 0}, {0, b, 0}, {0, 0, c}}], Assumptions -> {a, b, c}∈PositiveReals]//MatrixFormVerify that the matrix is symmetric:
SymmetricMatrixQ[%]Compute the kinetic energy if its angular velocity is
:
(1/2){Subscript[ω, x], Subscript[ω, y], Subscript[ω, z]}.%%.{Subscript[ω, x], Subscript[ω, y], Subscript[ω, z]}//FullSimplifyThe kinetic energy is positive as long as
is nonzero, showing the matrix was positive definite:
Resolve[Subscript[∀, {Subscript[ω, x], Subscript[ω, y], Subscript[ω, z], a, b, c}, {a, b, c}∈PositiveReals && {Subscript[ω, x], Subscript[ω, y], Subscript[ω, z]} ≠ {0, 0, 0}]% > 0]Determine if a sparse matrix is structurally symmetric:
ArrayPlot[m = SparseArray[{Band[{1, 2}] -> 1, Band[{2, 1}] -> -1}, {25, 25}]]SymmetricMatrixQ[m]But it is structurally symmetric:
SymmetricMatrixQ[Unitize[m]]Use a different method for symmetric matrices, with failover to a general method:
myLS[m_, b_] := Module[{x},
If[SymmetricMatrixQ[m],
(* "Cholesky" works for positive definite matrices only *)Quiet[x = LinearSolve[m, b, Method -> "Cholesky"]]];
If[!VectorQ[x], x = LinearSolve[m, b]];
x]Construct real-valued matrices for testing:
With[{n = 1000},
m = RandomReal[NormalDistribution[], {n, n}];
b = N[Range[n]];]For a non-symmetric matrix m, the function myLS just uses Gaussian elimination:
Timing[myLS[m, b];]For a symmetric indefinite matrix ms, try Cholesky and continue with Gaussian elimination:
ms = m + Transpose[m];Timing[myLS[ms, b];]For a symmetric positive-definite matrix mpd, try Cholesky, which succeeds:
mpd = m.Transpose[m];SymmetricMatrixQ[mpd]Timing[myLS[mpd, b];]Properties & Relations (14)
SymmetricMatrixQ[x] trivially returns False for any x that is not a matrix:
SymmetricMatrixQ[Sqrt[3]]A matrix is symmetric if mTranspose[m]:
m = (| | |
| ------- | ------- |
| 1 + I | 2 + 2 I |
| 2 + 2 I | 3 + 3 I |);{m == Transpose[m], SymmetricMatrixQ[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 to compute the symmetric part of a matrix:
m = RandomReal[1, {3, 3}];Symmetrize[m]This equals the average of m and Transpose[m]:
% == (m + m/2)Any matrix can be represented as the sum of its symmetric and antisymmetric parts:
m = RandomComplex[1 + I, {3, 3}];
{sym, asym} = {(m + m) / 2, (m - m) / 2};m == sym + asymUse AntisymmetricMatrixQ to test whether a matrix is antisymmetric:
{SymmetricMatrixQ[sym], AntisymmetricMatrixQ[asym]}If
is a symmetric matrix with real entries, then
is antihermitian:
m = Block[{a = RandomReal[1, {5, 5}]}, a + a^];{SymmetricMatrixQ[m], AntihermitianMatrixQ[I m]}MatrixExp[I m] for real symmetric m is unitary:
m = Symmetrize[RandomReal[1, {5, 5}]];UnitaryMatrixQ[MatrixExp[I m]]A real-valued symmetric matrix is always a normal matrix:
m = Block[{a = RandomReal[1, {10, 10}]}, a + a];{SymmetricMatrixQ[m], NormalMatrixQ[m]}A complex-valued symmetric matrix need not be normal:
c = (| | | |
| - | - | - |
| I | 0 | 1 |
| 0 | I | I |
| 1 | I | I |);{SymmetricMatrixQ[c], NormalMatrixQ[c]}Real-valued symmetric matrices have all real eigenvalues:
m = Block[{a = RandomReal[1, {5, 5}]}, a + a];SymmetricMatrixQ[m]Use Eigenvalues to find eigenvalues:
Eigenvalues[m]Note that a complex-valued symmetric matrix may have both real and complex eigenvalues:
Eigenvalues[(| | | |
| - | - | - |
| I | 0 | 1 |
| 0 | I | I |
| 1 | I | I |)]CharacteristicPolynomial[m,x] for real symmetric m can be factored into linear terms:
m = Block[{a = RandomReal[1, {3, 3}]}, a + a];Factor[CharacteristicPolynomial[m, x]]Real-valued symmetric matrices have a complete set of eigenvectors:
m = Block[{a = RandomReal[1, {3, 3}]}, a + a];SymmetricMatrixQ[m]As a consequence, they must be diagonalizable:
DiagonalizableMatrixQ[m]Use Eigenvectors to find eigenvectors:
Eigenvectors[m]//MatrixFormNote that a complex-valued symmetric matrix need not have these properties:
c = (| | | |
| - | - | - |
| I | 0 | 1 |
| 0 | I | I |
| 1 | I | I |);{SymmetricMatrixQ[c], DiagonalizableMatrixQ[c]}The inverse of a symmetric matrix is symmetric:
m = Block[{a = RandomComplex[1 + I, {3, 3}]}, a + a];SymmetricMatrixQ[Inverse[m]]Matrix functions of symmetric matrices are symmetric, including MatrixPower:
m = Block[{a = RandomReal[1, {3, 3}]}, a + a];SymmetricMatrixQ[MatrixPower[m, n]]SymmetricMatrixQ[MatrixExp[m]]And any univariate function representable using MatrixFunction:
SymmetricMatrixQ[MatrixFunction[Sin, m]]SymmetricMatrix can be used to explicitly construct symmetric matrices:
SymmetricMatrix[RandomVariate[GaussianOrthogonalMatrixDistribution[3]]]These satisfy SymmetricMatrixQ:
SymmetricMatrixQ[%]Possible Issues (1)
SymmetricMatrixQ uses the definition
for both real- and complex-valued matrices:
c = (| | | |
| - | - | - |
| I | 0 | 1 |
| 0 | I | I |
| 1 | I | I |);{SymmetricMatrixQ[c] , c == c}These complex matrices need not be normal or possess many properties of self-adjoint (real symmetric) matrices:
NormalMatrixQ[c]HermitianMatrixQ tests the condition
for self-adjoint matrices:
HermitianMatrixQ[c]Alternatively, test if the entries are real to restrict to real symmetric matrices:
symmetricMatrixQ[m_] := SymmetricMatrixQ[m] && Element[m, Reals]symmetricMatrixQ[c]Neat Examples (1)
Images of symmetric matrices including FourierMatrix:
m = FourierMatrix[45];SymmetricMatrixQ[m]MatrixPlot[N[m, 20]]Related Guides
Text
Wolfram Research (2008), SymmetricMatrixQ, Wolfram Language function, https://reference.wolfram.com/language/ref/SymmetricMatrixQ.html (updated 2014).
CMS
Wolfram Language. 2008. "SymmetricMatrixQ." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2014. https://reference.wolfram.com/language/ref/SymmetricMatrixQ.html.
APA
Wolfram Language. (2008). SymmetricMatrixQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SymmetricMatrixQ.html
BibTeX
@misc{reference.wolfram_2026_symmetricmatrixq, author="Wolfram Research", title="{SymmetricMatrixQ}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/SymmetricMatrixQ.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_symmetricmatrixq, organization={Wolfram Research}, title={SymmetricMatrixQ}, year={2014}, url={https://reference.wolfram.com/language/ref/SymmetricMatrixQ.html}, note=[Accessed: 12-June-2026]}