DiagonalMatrix

DiagonalMatrix[list]

gives a matrix with the elements of list on the leading diagonal, and zero elsewhere.

DiagonalMatrix[list,k]

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

DiagonalMatrix[list,k,n]

pads with zeros to create an n×n matrix.

Details

Examples

open allclose all

Basic Examples  (1)

Construct a diagonal matrix:

A superdiagonal matrix:

A subdiagonal matrix:

Scope  (4)

The elements in DiagonalMatrix are chosen to match the elements of the vector:

Exact number entries:

Machine-number entries:

Arbitrary-precision number entries:

When the vector is a SparseArray object, DiagonalMatrix will give a SparseArray object:

Pad with zeros to make a larger square matrix:

Make a square matrix with the specified dimension:

Rectangular diagonal matrices:

Applications  (5)

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

Verify the similarity of a matrix to the diagonal matrix of its eigenvalues:

Define a Jordan matrix:

Construct a 5×5 tridiagonal matrix:

This can also be done using Band:

Extract the diagonal from a diagonal rectangular matrix:

Reconstruct the original matrix from the diagonal:

Properties & Relations  (8)

IdentityMatrix is a special case of DiagonalMatrix:

DiagonalMatrix creates matrices that are DiagonalMatrixQ:

DiagonalMatrix[l] is UpperTriangularMatrixQ and LowerTriangularMatrixQ:

Several simple properties hold for diagonal matrices:

Inverse, MatrixExp, and MatrixPower commute with DiagonalMatrix:

Det and Tr have commuting relations:

Diagonal of DiagonalMatrix gives the original vector:

This is true even if the vector is a SparseArray object:

Matrices with only subdiagonals or superdiagonals are always nilpotent:

The size of the matrix generated by DiagonalMatrix[list,k] equals Length[list]+Abs[k]:

Band can be used to construct diagonals equivalent to DiagonalMatrix[list,k]:

They will be SameQ if the vector is a SparseArray:

Wolfram Research (1988), DiagonalMatrix, Wolfram Language function, https://reference.wolfram.com/language/ref/DiagonalMatrix.html (updated 2008).

Text

Wolfram Research (1988), DiagonalMatrix, Wolfram Language function, https://reference.wolfram.com/language/ref/DiagonalMatrix.html (updated 2008).

CMS

Wolfram Language. 1988. "DiagonalMatrix." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2008. https://reference.wolfram.com/language/ref/DiagonalMatrix.html.

APA

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

BibTeX

@misc{reference.wolfram_2022_diagonalmatrix, author="Wolfram Research", title="{DiagonalMatrix}", year="2008", howpublished="\url{https://reference.wolfram.com/language/ref/DiagonalMatrix.html}", note=[Accessed: 08-June-2023 ]}

BibLaTeX

@online{reference.wolfram_2022_diagonalmatrix, organization={Wolfram Research}, title={DiagonalMatrix}, year={2008}, url={https://reference.wolfram.com/language/ref/DiagonalMatrix.html}, note=[Accessed: 08-June-2023 ]}