Derive a Least-Squares Solution 

Fit a line to data using the method of least squares.

Define the sum of squares of the vertical deviations for a given set of data.

In[1]:=
Click for copyable input
X
Out[1]=

Set up the equations for minimum deviation.

In[2]:=
Click for copyable input
X
Out[2]=
In[3]:=
Click for copyable input
X
Out[3]=

Generate some data.

In[4]:=
Click for copyable input
X

Solve the least-squares problem for this data.

In[5]:=
Click for copyable input
X
Out[5]=

Plot the solution along with the data and verify they match.

In[6]:=
Click for copyable input
X
Out[6]=
de es ja pt-br zh