# Trace of a matrix (trace)

Trace of a square matrix: the sum of its diagonal.

## How to write it

### trace(matrix)

**matrix**

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

## Examples

- $\displaystyle \operatorname{tr}\left(\begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}\right) = 5$

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

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

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

## Related functions

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

  Transpose of a matrix: its rows become its columns.
- [tensor_product](https://hilberon.com/library/tensor_product)

  Tensor product of two lists or matrices.
- [upper_triangularize](https://hilberon.com/library/upper_triangularize)

  A matrix with the entries below the diagonal set to zero.
- [smith_decomposition](https://hilberon.com/library/smith_decomposition)

  Smith normal form of an integer matrix, with the two matrices that reach it.
- [adjugate](https://hilberon.com/library/adjugate)

  Adjugate of a square matrix: the transpose of its cofactors.
- [singular_value_list](https://hilberon.com/library/singular_value_list)

  The singular values of a matrix.

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