# Least squares fit (least_squares)

The least-squares solution of A x = b.

## How to write it

### least_squares(matrix, b)

**matrix**

The matrix A. Takes a matrix, written as a list of rows.

**b**

The right-hand side, as a list. Takes a list.

## Examples

- $\displaystyle \operatorname{least\_squares}\left(\begin{pmatrix} 1 & 0 \\ 1 & 1 \\ 1 & 2 \end{pmatrix}, \left[ 1, 2, 4 \right]\right) = \left[ \frac{5}{6}, \frac{3}{2} \right]$

  `least_squares([[1, 0], [1, 1], [1, 2]], [1, 2, 4])`

  In the solver, `least_squares([[1, 0], [1, 1], [1, 2]], [1, 2, 4])` gives `[5/6, 3/2]`.

  [Open in the solver](https://hilberon.com/?q=least_squares%28%5B%5B1%2C%200%5D%2C%20%5B1%2C%201%5D%2C%20%5B1%2C%202%5D%5D%2C%20%5B1%2C%202%2C%204%5D%29)

## Related functions

- [linear_solve](https://hilberon.com/library/linear_solve)

  Solve a linear system A x = b given by its matrix and right-hand side.
- [find_root](https://hilberon.com/library/find_root)

  Find a root numerically, from a starting value.
- [numeric_solve](https://hilberon.com/library/numeric_solve)

  Solve equations numerically.
- [find_instance](https://hilberon.com/library/find_instance)

  A point that meets a condition, or an empty list when there is none.
- [solve](https://hilberon.com/library/solve)

  Solve equations for one or more unknowns.
- [eliminate](https://hilberon.com/library/eliminate)

  Eliminate variables from a system of equations, leaving equations in the others.

---
Source: https://hilberon.com/library/least_squares
