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.

DetailsDetails

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

ExamplesExamplesopen allclose all

Basic Examples (3)Basic Examples (3)

Give the diagonal elements of a matrix:

In[1]:=
Click for copyable input
Out[1]=

Give diagonals one element above and below the leading diagonal:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=

Give a diagonal of a nonsquare matrix:

In[1]:=
Click for copyable input
Out[1]=
New in 6
New to Mathematica? Find your learning path »
Have a question? Ask support »