--- layout: default ---

Function eigs #

Compute eigenvalues and optionally eigenvectors of a square matrix. The eigenvalues are sorted by their absolute value, ascending, and returned as a vector in the `values` property of the returned project. An eigenvalue with algebraic multiplicity k will be listed k times, so that the returned `values` vector always has length equal to the size of the input matrix. The `eigenvectors` property of the return value provides the eigenvectors. It is an array of plain objects: the `value` property of each gives the associated eigenvalue, and the `vector` property gives the eigenvector itself. Note that the same `value` property will occur as many times in the list provided by `eigenvectors` as the geometric multiplicity of that value. If the algorithm fails to converge, it will throw an error – in that case, however, you may still find useful information in `err.values` and `err.vectors`. Note that the 'precision' option does not directly specify the _accuracy_ of the returned eigenvalues. Rather, it determines how small an entry of the iterative approximations to an upper triangular matrix must be in order to be considered zero. The actual accuracy of the returned eigenvalues may be greater or less than the precision, depending on the conditioning of the matrix and how far apart or close the actual eigenvalues are. Note that currently, relatively simple, "traditional" methods of eigenvalue computation are being used; this is not a modern, high-precision eigenvalue computation. That said, it should typically produce fairly reasonable results.

Syntax #

```js math.eigs(x, [prec]) math.eigs(x, {options}) ```

Parameters #

Parameter | Type | Description --------- | ---- | ----------- `x` | Array | Matrix | Matrix to be diagonalized `opts` | number | BigNumber | OptsObject | Object with keys `precision`, defaulting to config.relTol, and `eigenvectors`, defaulting to true and specifying whether to compute eigenvectors. If just a number, specifies precision.

Returns #

Type | Description ---- | ----------- {values: Array | Matrix, eigenvectors?: Array<EVobj>}} Object containing an array of eigenvalues and an array of {value: number | BigNumber, vector: Array | Matrix | objects. The eigenvectors property is undefined if eigenvectors were not requested.

Throws #

Type | Description ---- | -----------

Examples #

```js const { eigs, multiply, column, transpose, matrixFromColumns } = math const H = [[5, 2.3], [2.3, 1]] const ans = eigs(H) // returns {values: [E1,E2...sorted], eigenvectors: [{value: E1, vector: v2}, {value: e, vector: v2}, ...] const E = ans.values const V = ans.eigenvectors multiply(H, V[0].vector)) // returns multiply(E[0], V[0].vector)) const U = matrixFromColumns(...V.map(obj => obj.vector)) const UTxHxU = multiply(transpose(U), H, U) // diagonalizes H if possible E[0] == UTxHxU[0][0] // returns true always // Compute only approximate eigenvalues: const {values} = eigs(H, {eigenvectors: false, precision: 1e-6}) ```

See also #

[inv](inv.html)