This question is most likely extremely trivial, but I'm having some difficulty obtaining the least squares equation from the following data points:
{{1.08, 0}, {1.07, 0.0659232}, {0.97, 0.1695168}, {0.77, 0.188352}, {0.84, 0.0847584}}
In particular, I'm trying to obtain a quadratic equation using least squares, so I was wondering if someone could show me the method they used to obtain it.
I have based my working (and obtained the data above) from the following link: http://www.maths.manchester.ac.uk/~pjohnson/resources/math60082/lecture-monte-carlo-ls.pdf
and I have tried to obtain the least squares equation by using the method as given on slide 14.
My working is given as follows:
Firstly, since I am trying to find a quadratic least squares form, I must solve three equations and attempt to find the coefficients $a_{0}, a_{1}, a_{2}$. Using the equations on slide 14 given in the link above, I then plug in the data points I was given into the equations, which are now given below:
(0 + .07*.94176 + .18*.94176 +.20*.94176 + .09*.94176) = 5*$a_{0}$ + $a_{1}$*(1.08 + 1.07 + .97 + .77 + .84)+$a_{2}$*(1.08^2 + 1.07^2 + .97^2 + .77^2 + .84^2)
(0*1.08 + .07*.94176*1.07 + .18*.94176*.97 +.20*.94176* .77 + .09*.94176*.84) = $a_{0}$*(1.08 + 1.07 + .97 + .77 + .84)+$a_{1}$*(1.08^2 + 1.07^2 +.97^2 + .77^2 + .84^2)+$a_{2}$*(1.08^3 + 1.07^3 + .97^3 + .77^3 + .84^3)
(.07*.94176*1.07^2+.18*.94176*.97^2+.20*.94176*.77^2+.09*.94176*.84^2) = $a_{0}$*(1.08^2 + 1.07^2 + .97^2 + .77^2 + .84^2)+$a_{1}$*(1.08^3 + 1.07^3 + .97^3 + .77^3+.84^3)+$a_{2}$*(1.08^4+1.07^4+.97^4 + .77^4 + .84^4)
However, putting this into Wolfram Alpha gives coefficient values -1.13685, 3.12955, and -1.89201, which are incorrect, since the quadratic equation should be -1.81357x^2 + 2.9834x - 1.06998.
If it's not too much trouble could someone please show me how to obtain the quadratic equation using least squares, or at least show me what I've done wrong?
Thanks in advance
I formulated it a bit different, but you should be able to follow along as all of these calculations will be identical to what you should be getting. I used page 30 as a guide.
We have $m = 2, n = 5$ and the data $(x_i, y_i)$ pairs are:
$$\text{data}=\left( \begin{array}{cc} 1.08 & 0 \\ 1.07 & 0.0659232 \\ 0.97 & 0.169517 \\ 0.77 & 0.188352 \\ 0.84 & 0.0847584 \\ \end{array} \right)$$
We have:
We now solve the linear system:
$$\left( \begin{array}{ccc} 5 & 4.73 & 4.5507 \\ 4.73 & 4.5507 & 4.44666 \\ 4.5507 & 4.44666 & 4.40598 \\ \end{array} \right)\left( \begin{array}{ccc} a_0 \\ a_1 \\ a_2 \\ \end{array} \right) = \left( \begin{array}{ccc} 0.5085504000000001 \\ 0.451197216 \\ 0.40645325664 \end{array} \right)$$
This gives the least squares coefficients as:
$$a_0 = -1.06998, a_1 = 2.9834, a_2 = -1.81357$$
Update
I used your equations (with some slight editing) in Mathematica and got the correct result. Are you sure Wolfram Alpha isn't cutting off part of the equations?
Here is the Mathematica input and results:
Output:
$$\{\{\text{a0}\to -1.06998,\text{a1}\to 2.9834,\text{a2}\to -1.81357\}\}$$