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