DiagonalMatrix

DiagonalMatrix[list]
gives a matrix with the elements of list on the leading diagonal, and 0 elsewhere.

DiagonalMatrix[list,k]
gives a matrix with the elements of list on the k^(th) diagonal.

DiagonalMatrix[list,k,n]
pads with 0s to create an n×n matrix.

DetailsDetails

ExamplesExamplesopen allclose all

Basic Examples  (1)Basic Examples  (1)

Construct a diagonal matrix:

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

A superdiagonal matrix:

In[2]:=
Click for copyable input
Out[2]//MatrixForm=

A subdiagonal matrix:

In[3]:=
Click for copyable input
Out[3]//MatrixForm=
Introduced in 1988
(1.0)
| Updated in 2008
(7.0)