mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-25 15:07:57 +00:00
1.0 KiB
1.0 KiB
| layout |
|---|
| default |
Function trace #
Calculate the trace of a matrix: the sum of the elements on the main diagonal of a square matrix.
Syntax #
math.trace(x)
Parameters #
| Parameter | Type | Description |
|---|---|---|
x |
Array | Matrix | A matrix |
Returns #
| Type | Description |
|---|---|
| number | The trace of x |
Examples #
math.trace([[1, 2], [3, 4]]) // returns 5
const A = [
[1, 2, 3],
[-1, 2, 3],
[2, 0, 3]
]
math.trace(A) // returns 6