# diagonal_matrix function

A matrix with the given list on its diagonal and zeros elsewhere.

## How to write it

### diagonal_matrix(list)

**list**

The diagonal. Takes a list.

## Examples

- $\displaystyle \operatorname{diagonal\_matrix}(\left[ 1, 2 \right]) = \begin{pmatrix} 1 & 0 \\ 0 & 2 \end{pmatrix}$

  `diagonal_matrix([1, 2])`

  In the solver, `diagonal_matrix([1, 2])` gives `[[1, 0], [0, 2]]`.

  [Open in the solver](https://hilberon.com/?q=diagonal_matrix%28%5B1%2C%202%5D%29)

## Related functions

- [diagonal](https://hilberon.com/library/diagonal)

  The diagonal of a matrix, as a list.
- [hilbert_matrix](https://hilberon.com/library/hilbert_matrix)

  Hilbert matrix of a given size: the entry in row i and column j is 1/(i + j - 1).
- [identity_matrix](https://hilberon.com/library/identity_matrix)

  Identity matrix of a given size.
- [matrix_exp](https://hilberon.com/library/matrix_exp)

  Exponential of a square matrix.
- [matrix_function](https://hilberon.com/library/matrix_function)

  A function of a square matrix.
- [matrix_log](https://hilberon.com/library/matrix_log)

  Logarithm of a square matrix.

---
Source: https://hilberon.com/library/diagonal_matrix
