gives True if m is diagonal, and False otherwise.


gives True if m has nonzero elements only on the k^(th) diagonal, and False otherwise.

Details and Options

  • DiagonalMatrixQ[m,k] works even if m is not a square matrix.
  • In DiagonalMatrixQ[m,k], positive k refers to superdiagonals above the main diagonal and negative k refers to subdiagonals below the main diagonal.
  • DiagonalMatrixQ works with SparseArray and structured array objects.
  • For approximate matrices, the option Tolerance->t can be used to indicate that all entries Abs[mij]t are taken to be zero.


open allclose all

Basic Examples  (3)

Test if a matrix is diagonal:

Test a superdiagonal matrix:

Test a subdiagonal matrix:

Scope  (12)

Basic Uses (8)

Test rectangular diagonal matrices:

Use DiagonalMatrixQ with a symbolic matrix:

The matrix becomes diagonal when :

Test if a real machine-precision matrix is diagonal:

Test if a complex matrix is diagonal:

The real part of the matrix is diagonal and the imaginary part is superdiagonal:

Test if an exact matrix is diagonal:

Use DiagonalMatrixQ with an arbitrary-precision matrix:

A random matrix is typically non-diagonal:

Test if matrices have nonzero entries only on a particular superdiagonal:

Note that the matrix is not diagonal:

Test if matrices have nonzero entries only on a particular subdiagonal:

Note that the matrix is not diagonal:

Special Matrices (4)

Use DiagonalMatrixQ with sparse matrices:

Use DiagonalMatrixQ with structured matrices:

Use with a QuantityArray structured matrix:

The identity matrix is diagonal:

HilbertMatrix is not diagonal:

Options  (1)

Tolerance  (1)

This matrix is not diagonal:

Add the Tolerance option to consider numbers smaller than 10-12 to be zero:

Applications  (2)

A real-valued matrix is orthogonally similar to a diagonal matrix iff it is normal and has real eigenvalues:

Compute the eigenvalues and eigenvectors of m:

The eigenvalues are real:

Verify that m is equivalent to a diagonal matrix via its eigenvectors:

Verify that the eigenvector matrix is orthogonal:

A matrix is diagonalizable if and only if its canonical Jordan matrix is diagonal:

Properties & Relations  (10)

DiagonalMatrixQ returns False for inputs that are not matrices:

Matrices of dimensions {n,0} are diagonal:

DiagonalMatrix creates a diagonal matrix:

Any identity matrix is diagonal:

Inverses of diagonal matrices are diagonal:

This extends to arbitrary powers and functions:

The product of two (or more) diagonal matrices is diagonal:

A diagonal matrix is both upper and lower triangular:

DiagonalMatrixQ[m,0] is equivalent to DiagonalMatrixQ[m]:

A matrix with only subdiagonals or superdiagonals is nilpotent, meaning for some :

Band can be used to construct a k-diagonal sparse matrix:

Wolfram Research (2019), DiagonalMatrixQ, Wolfram Language function, https://reference.wolfram.com/language/ref/DiagonalMatrixQ.html.


Wolfram Research (2019), DiagonalMatrixQ, Wolfram Language function, https://reference.wolfram.com/language/ref/DiagonalMatrixQ.html.


Wolfram Language. 2019. "DiagonalMatrixQ." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/DiagonalMatrixQ.html.


Wolfram Language. (2019). DiagonalMatrixQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/DiagonalMatrixQ.html


@misc{reference.wolfram_2022_diagonalmatrixq, author="Wolfram Research", title="{DiagonalMatrixQ}", year="2019", howpublished="\url{https://reference.wolfram.com/language/ref/DiagonalMatrixQ.html}", note=[Accessed: 07-October-2022 ]}


@online{reference.wolfram_2022_diagonalmatrixq, organization={Wolfram Research}, title={DiagonalMatrixQ}, year={2019}, url={https://reference.wolfram.com/language/ref/DiagonalMatrixQ.html}, note=[Accessed: 07-October-2022 ]}