> ## Documentation Index
> Fetch the complete documentation index at: https://docs.0xarchive.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Matrices (linalg)

> Matrices, products, solves and the Cholesky, QR, eigen and singular value decompositions.

Results are the same bits in every browser; a decomposition takes steps from the budget in proportion to its work (about n³). Eigenvectors and right singular vectors have their largest entry positive, so they don't flip between bars.

## linalg

**mat()** `(rows: number, cols: number, values?: readonly number[] | readonly (readonly number[])[]): Mat`

A matrix of zeros, or of `values` given row by row (flat, or as a list of rows). At most 512 rows or columns.

**identity()** `(n: number): Mat`

**mul()** `(a: Mat, b: Mat): Mat`

**mul()** `(a: Mat, x: readonly number[]): readonly number[]`

A matrix times a vector.

**transpose()** `(a: Mat): Mat`

**add()** `(a: Mat, b: Mat): Mat`

**sub()** `(a: Mat, b: Mat): Mat`

**scale()** `(a: Mat, k: number): Mat`

**solve()** `(a: Mat, b: Mat): Mat`

x with a·x = b, by LU with pivoting; `na` throughout when `a` is singular.

**solve()** `(a: Mat, b: readonly number[]): readonly number[]`

**inv()** `(a: Mat): Mat`

The inverse; `na` throughout when `a` is singular.

**cholesky()** `(a: Mat): Mat`

The lower factor L of a = L·Lᵀ; `na` throughout when `a` is not positive definite.

**qr()** `(a: Mat): \{ readonly q: Mat; readonly r: Mat \}`

Reduced QR: q is rows × k and r is k × cols, k the smaller of the two, with a non-negative diagonal in r.

**eigSym()** `(a: Mat): \{ readonly values: readonly number[]; readonly vectors: Mat \}`

Symmetric matrices only: eigenvalues largest first, unit eigenvectors as the columns of `vectors`.

**svd()** `(a: Mat): \{ readonly u: Mat; readonly s: readonly number[]; readonly v: Mat \}`

Reduced SVD, a = u · diag(s) · vᵀ, singular values largest first.

## Mat

A matrix: rows × columns of numbers.

**rows** `number`

**cols** `number`

**get()** `(row: number, col: number): number`

**set()** `(row: number, col: number, value: number): void`

**row()** `(index: number): readonly number[]`

**col()** `(index: number): readonly number[]`

**toArray()** `(): number[][]`

## StateMat

A matrix kept across bars (`state.mat`).

**assign()** `(source: Mat): void`

Copy every entry of a matrix of the same shape.

**fill()** `(value: number): void`

## Next step

Continue with [Plots](https://docs.0xarchive.io/terminal/reference/plots.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.