Returns the eigenvalues of a square matrix as an array of floats.
Eigenvalues are the scale factors along the matrix's characteristic directions. For a covariance matrix they are the variances along its principal axes.
Their sum equals the trace and their product equals the determinant, which makes a handy check. For a diagonal or triangular matrix they are the diagonal items themselves, so [[3, 0], [0, 1]] has eigenvalues 3 and 1.
Syntax
matrix.eigenvalues(id: matrix<int/float>) -> array<float>
matrix.eigenvalues(id: matrix<int>) -> array<int>
matrix.eigenvalues() -> array<float>
matrix.eigenvalues() -> array<int>Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | matrix<int/ | required | The square matrix to decompose; one eigenvalue comes back for each of its rows. |
Returns
array<float>: One eigenvalue per row of the matrix, as floats.array<int>: One eigenvalue per row, held in an integer array, so values with decimals need a decimal-valued matrix.array<float>: The eigenvalues of the receiving matrix, one per row, as floats.array<int>: The eigenvalues of the receiving matrix, held in an integer array.
Remarks
- On Sidechair: the values come back smallest first, and a complex eigenvalue is na.
Example
//@version=6
indicator("matrix.eigenvalues: top variance", overlay = false)
matrix<float> cov = matrix.new<float>(2, 2, 0.0)
matrix.set(cov, 0, 0, 3.0)
matrix.set(cov, 1, 1, 1.0)
plot(array.max(matrix.eigenvalues(cov)), "Largest eigenvalue")See also
Runs on Sidechair