Function reference · Linear algebra

trace

Returns the trace of a square matrix: the sum of its diagonal entries.

Notation

trace(matrix)

Write it in an expression: nerdamer('trace(matrix([1,2],[3,4]))'), or in the Playground.

nerdamer.trace

nerdamer.trace(...args: [M]): Expression

A method on the default import. Arguments can be strings, as in Notation.

Parameters

matrix
A square matrix.

Returns

The sum of the diagonal entries.

Examples

1 + 4.

trace(matrix([1,2],[3,4]))
// → 5
Open in Playground

Symbolic entries work.

trace(matrix([a,b],[c,d]))
// → a+d
Open in Playground

The 3 by 3 identity matrix has trace 3.

trace(imatrix(3))
// → 3
Open in Playground

Good to know

  • A matrix that isn't square is an error.

JavaScript examples

nerdamer.trace('matrix([1,2],[3,4])').text()
// → 5

← Back to Function reference