UNPKG

652 BMarkdownView Raw
1<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
2
3# Function trace
4
5Calculate the trace of a matrix: the sum of the elements on the main
6diagonal of a square matrix.
7
8
9## Syntax
10
11```js
12math.trace(x)
13```
14
15### Parameters
16
17Parameter | Type | Description
18--------- | ---- | -----------
19`x` | Array &#124; Matrix | A matrix
20
21### Returns
22
23Type | Description
24---- | -----------
25number | The trace of `x`
26
27
28## Examples
29
30```js
31math.trace([[1, 2], [3, 4]]) // returns 5
32
33const A = [
34 [1, 2, 3],
35 [-1, 2, 3],
36 [2, 0, 3]
37]
38math.trace(A) // returns 6
39```
40
41
42## See also
43
44[diag](diag.md)