1 |
|
2 |
|
3 | # Function eigs
|
4 |
|
5 | Compute eigenvalues and eigenvectors of a matrix. The eigenvalues are sorted by their absolute value, ascending.
|
6 | An eigenvalue with multiplicity k will be listed k times. The eigenvectors are returned as columns of a matrix –
|
7 | the eigenvector that belongs to the j-th eigenvalue in the list (eg. `values[j]`) is the j-th column (eg. `column(vectors, j)`).
|
8 | If the algorithm fails to converge, it will throw an error – in that case, however, you may still find useful information
|
9 | in `err.values` and `err.vectors`.
|
10 |
|
11 |
|
12 | ## Syntax
|
13 |
|
14 | ```js
|
15 | math.eigs(x, [prec])
|
16 | ```
|
17 |
|
18 | ### Parameters
|
19 |
|
20 | Parameter | Type | Description
|
21 | --------- | ---- | -----------
|
22 | `x` | Array | Matrix | Matrix to be diagonalized
|
23 | `prec` | number | BigNumber | Precision, default value: 1e-15
|
24 |
|
25 | ### Returns
|
26 |
|
27 | Type | Description
|
28 | ---- | -----------
|
29 | {values: Array | Matrix, vectors: Array | Matrix} | Object containing an array of eigenvalues and a matrix with eigenvectors as columns.
|
30 |
|
31 |
|
32 | ## Examples
|
33 |
|
34 | ```js
|
35 | const { eigs, multiply, column, transpose } = math
|
36 | const H = [[5, 2.3], [2.3, 1]]
|
37 | const ans = eigs(H) // returns {values: [E1,E2...sorted], vectors: [v1,v2.... corresponding vectors as columns]}
|
38 | const E = ans.values
|
39 | const U = ans.vectors
|
40 | multiply(H, column(U, 0)) // returns multiply(E[0], column(U, 0))
|
41 | const UTxHxU = multiply(transpose(U), H, U) // diagonalizes H
|
42 | E[0] == UTxHxU[0][0] // returns true
|
43 | ```
|
44 |
|
45 |
|
46 | ## See also
|
47 |
|
48 | [inv](inv.md)
|