Least Squares Approximation

We derived the normal equations to solve the approximation by least squares. Below is the output of the example we worked out in class with MATLAB.
>> % In case of overconstrained systems, MATLAB automatically
>> % returns the least squares solution, for example
>> A = [1 0; 1 1; 1 2]

A =

     1     0
     1     1
     1     2

>> b = [1; 1; 2]

b =

     1
     1
     2

>> x = A\b

x =

    0.8333
    0.5000

>> % Let us check the solution of the normal equations:
>> AA = A'*A

AA =

     3     3
     3     5

>> Ab = A'*b

Ab =

     4
     5

>> y = AA\Ab

y =

    0.8333
    0.5000

>> norm(x-y)

ans =

   8.3267e-16

>> diary off