# diagonal function

The diagonal of a matrix, as a list.

## How to write it

### diagonal(matrix)

**matrix**

A matrix, written as a list of rows. Takes a matrix, written as a list of rows.

## Examples

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

  `diagonal([[1, 2], [3, 4]])`

  In the solver, `diagonal([[1, 2], [3, 4]])` gives `[1, 4]`.

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

## Related functions

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

  A matrix with the given list on its diagonal and zeros elsewhere.
- [det](https://hilberon.com/library/det)

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

  Dot product of two vectors, or product of two matrices.
- [cross](https://hilberon.com/library/cross)

  Cross product of two vectors in three dimensions.
- [eigensystem](https://hilberon.com/library/eigensystem)

  Eigenvalues and eigenvectors of a square matrix together: the values, then the vectors.
- [cholesky_decomposition](https://hilberon.com/library/cholesky_decomposition)

  Cholesky decomposition of a symmetric positive definite matrix.

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