# DiagonalMatrixQ

gives True if m is diagonal, and False otherwise.

DiagonalMatrixQ[m,k]

gives True if m has nonzero elements only on the k 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.

# Examples

open allclose all

## Basic Examples(3)

Test if a matrix is diagonal:

Test a superdiagonal matrix:

Test a subdiagonal matrix:

## Scope(7)

Test if a real machine-number matrix is diagonal:

A complex matrix:

An exact matrix:

An arbitrary-precision matrix:

Test a sparse matrix:

Test whether an antisymmetric matrix is diagonal:

Test a symbolic matrix:

The matrix becomes diagonal when b=c=0:

Test rectangular diagonal matrices:

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

The following matrix is diagonal but not superdiagonal:

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

The following matrix is diagonal but not subdiagonal:

## 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 :

Matrices with only subdiagonals or superdiagonals are always nilpotent:

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

Introduced in 2019
(12.0)