Diagonal

Diagonal[m]

gives the list of elements on the leading diagonal of the matrix m.

Diagonal[m,k]

gives the elements on the k^(th) diagonal of m.

Details

  • Diagonal[m] works even if m is not a square matrix.
  • For positive k, Diagonal[m,k] gives diagonals above the leading diagonal. Diagonal[m,-k] gives diagonals below.

Examples

open allclose all

Basic Examples  (4)

Give the diagonal elements of a matrix:

Obtain the superdiagonal:

Obtain the subdiagonal:

Give a diagonal of a nonsquare matrix:

Scope  (12)

Basic Uses  (7)

Find the diagonal of a machine-precision matrix:

The superdiagonal of a complex matrix:

Diagonal of an exact matrix:

Diagonal of an arbitrary-precision matrix:

The diagonal of a symbolic matrix that is two below the main diagonal:

Diagonal accepts non-square matrices:

Extraction of the diagonal of a large matrix is efficient:

Special Matrices  (5)

The diagonal of a sparse matrix is returned as a sparse list:

Convert the result to an ordinary list:

Get all the diagonals of the sparse array:

Convert the results to an ordinary list:

The diagonals of structured matrices:

IdentityMatrix has a diagonal of all ones:

Diagonal of HilbertMatrix:

Applications  (3)

Express a matrix as the sum of its diagonal and off-diagonal parts:

The diagonal part:

Construct the diagonal as the difference between the original matrix and its diagonal part:

Confirm that two matrices have the desired properties:

Determine if the matrix is diagonalizable using its Jordan decomposition:

The superdiagonal of the Jordan form does not consist solely of zeros, so is not diagonalizable:

Confirm with a direct call to DiagonalizableMatrixQ:

Find the eigenvalues of the matrix using its Jordan decomposition:

The diagonal of the Jordan form gives the eigenvalues:

Confirm with a direct call to Eigenvalues:

Properties & Relations  (7)

For square m, DiagonalMatrix[Diagonal[m]]==m iff DiagonalMatrixQ[m] is True:

For a matrix m, Tr[m] can be expressed as a combination of Diagonal and Total:

Diagonal[m,k] for an n×n matrix gives non-empty results for 1-n<=k<=n-1:

Diagonal[m,k] gives the lowest nonzero diagonal of UpperTriangularize[m,k]:

Similarly, Diagonal[m,k] gives the highest nonzero diagonal of LowerTriangularize[m,k]:

A matrix can be reconstructed from its diagonals using Band:

For a matrix m, Diagonal[m] is equivalent to Tr[m,List]:

For a square matrix m, Diagonal[m] is equivalent to Transpose[m,{1,1}]:

Neat Examples  (1)

Subdiagonal and superdiagonals:

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

Text

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

CMS

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

APA

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

BibTeX

@misc{reference.wolfram_2023_diagonal, author="Wolfram Research", title="{Diagonal}", year="2007", howpublished="\url{https://reference.wolfram.com/language/ref/Diagonal.html}", note=[Accessed: 28-March-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_diagonal, organization={Wolfram Research}, title={Diagonal}, year={2007}, url={https://reference.wolfram.com/language/ref/Diagonal.html}, note=[Accessed: 28-March-2024 ]}