**Chapter
8. **** Least Squares** (.NET, C#, CSharp, VB, Visual Basic, F#)

**NMath** provides
classes for computing the minimum-norm solution to a linear system Ax = y. In a linear model, a quantity y depends on one or more independent variables
a_{1}, a_{2},...,a_{n}
such that y = x_{0} + x_{1}a_{1} + ... + x_{n}a_{n}. (Parameter
x_{0}
is called the *intercept parameter*.)
The goal of a least squares problem is to solve for the best values of
x_{0}, x_{1},...,x_{n}.

Several observations of the independent values a_{i} are
recorded, along with the corresponding values of the dependent variable
y. If m observations
are performed, and for the *i*th observation
we denote the values of the independent variables a_{i1}, a_{i2},...,a_{in}_{ }and the corresponding
dependent value of y as y_{i}, then we form the linear system Ax = y, where A = (a_{ij}) and
y = (y_{i}). The general least squares solution is the value
of x that minimizes ||Ax
- y||. The nonnegative least squares solution
is the value of x subject to the constraint
that each element of x is nonnegative.

Note that if the model contains a non-zero intercept parameter, then the first column of A is all ones.

The **NMath**
least squares classes use a complete orthogonal factorization of A to compute the solution. Matrix A is rectangular, and may be rank deficient.