Page 1 of 1

### find the least squares straight line fit to four points

Posted: Mon 13 June, 2011 11:32
Exercise set 6.5 (elementary linear Algebra Anton, Rorres 10E)
2. find the least squares straight line fit to four points (0,1), (2,0), (3,1) and (3,2).
This question asks for the equation of straight line that fits those points. The equation would be in the form `y=a+bx` and we are going to find `a` and `b` where v*`=[[a],[b]]`

Using the formula v*=`(M^TM)^(-1) M^Ty` we can solve by defining the M and y.

M is the matrix in the form
`M=[[1, x_1],[1, x_2],[1, x_3],[1, x_4]]`

the `x_1, x_2, x_3 and x_4` are the x values of the points (0,1), (2,0), (3,1) and (3,2)
`M=[[1, 0],[1, 2],[1, 3],[1,3]]`

and then we have y matrix with all y values from the points

`y=[[1],[0],[1],[2]]`

using our formula v*=`(M^TM)^(-1) M^Ty` we first do `M^T`
`M^T=[[1,1,1,1],[0,2,3,3]]`
`M^TM=[[1,1,1,1],[0,2,3,3]] * [[1, 0],[1, 2],[1, 3],[1,3]]=[[4,8],[8,22]]`

and taking the inverse of ` [[4,8],[8,22]]^-1=1/((4)(22)-(8)(8))*[[22,4],[-8,-8]]=[[11/2, -1/3],[-1/3,1/6]]`

Now `[[11/2, -1/3],[-1/3,1/6]]*M^Ty=[[11/2, -1/3],[-1/3,1/6]]*[[1, 0],[1, 2],[1, 3],[1,3]]*[[1],[0],[1],[2]]=[[2/3],[1/6]]`

we found the v*`[[a],[b]]=[[2/3],[1/6]]` therefore the a=2/3 and b is 1/6 and the equation for the least squares straight line to fit is:`y=2/3+ 1/6x`