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


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


  • 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.


open allclose all

Basic Examples  (3)

Give the diagonal elements of a matrix:

Give diagonals one element above and below the leading diagonal:

Give a diagonal of a nonsquare matrix:

Properties & Relations  (3)

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

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:

Introduced in 2007