# 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 diagonal.

DiagonalMatrix[list,k,n]

pads with 0s to create an n×n matrix.

# Details • For positive k, DiagonalMatrix[list,k] puts the elements k positions above the main diagonal. DiagonalMatrix[list,-k] puts the elements k positions below.
• DiagonalMatrix[list,k] fills the k diagonal of a square matrix with the elements from list. Different values of k lead to different matrix dimensions.
• DiagonalMatrix[list,k,n] always creates an n×n matrix, even if this requires dropping elements of list. »
• DiagonalMatrix[list,k,{m,n}] creates an m×n matrix.
• DiagonalMatrix[SparseArray[],] gives a SparseArray object.

# Examples

open all close all

## Basic Examples(1)

Construct a diagonal matrix:

 In:= Out//MatrixForm= A superdiagonal matrix:

 In:= Out//MatrixForm= A subdiagonal matrix:

 In:= Out//MatrixForm= ## Properties & Relations(8)

Introduced in 1988
(1.0)
|
Updated in 2008
(7.0)