Least squares to matrix to poly coefficients

I am writing programming code to develop a polynomial equation from x,y data. I am using the least squares procedure to develop various sums to fill a matrix. Once the matrix is filled, computing poly coefficients is straight forward matrix algebra.

I have 29 reps of data that look like:

Rep x_{1} x_{2} x_{3} y

——————————————————————————————————————————

1

2

…

29

——————————————————————————————————————————

x_{2} and x_{3} have the form:

x_{2} = x_{1}^2

x_{3} = x_{1}^3

My problem is figuring out how to fill the 3x3 matrix cells that take the sum of products (SP).

The diagonal cells take the sum of squares (SS) which is:

SS = ∑X^{2} - (∑x)^{2}/n This is for cells (1,1), (2,2) and (3,3), using x_{1}, x_{2} and x_{3} respectively.

The non-diagonal cells take the sum of products (SP) which is:

SP = ∑(x_{1}*x_{2}) - ((∑x_{1})(∑x_{2}))/n This is for cell (1,2)

The mirror cells are:

(2,1) = (1,2)

(3,1) = (1,3)

(3,2) = (2,3)

So the matrix I now have is:

∑X_{1}^{2} - (∑x_{1})^{2}/n | ∑(x_{1}*x_{2})-((∑x_{1})(∑x_{2}))/n | ??? |

mirror of cell (1,2) | ∑X_{2}^{2} - (∑x_{2})^{2}/n | ??? |

mirror of cell (1,3) | mirror of cell (2,3) | ∑X_{3}^{2} - (∑x_{3})^{2}/n |

The question marks are where I’m stumped. This procedure works great for a 2x2 matrix and a 2nd degree polynomial. But now I’m expanding to a 3x3 matrix for a 3rd degree polynomial. I’ve tried every combo of SP’s for cells (1,3) and (2,3), but to no avail.

I suspect this is simple, and aesthetically pleasing. I have not found the answer in the literature.

Any help is appreciated.

TJ

Re: Least squares to matrix to poly coefficients

Murphy’s Law

I should have guessed. As soon as I join Math Forum, I figure out the problem. I had an error in the way I was transposing x data, which was showing up as a matrix error. The sum of products (SP) that I tried and failed, was really the right solution.

Here is the final least squares matrix for solving a 3rd degree polynomial:

∑X12 - (∑x1)2/n ∑(x1*x2)-((∑x1)(∑x2))/n ∑(x1*x3)-((∑x1)(∑x3))/n

mirror of cell (1,2) ∑X22 - (∑x2)2/n ∑(x2*x3)-((∑x2)(∑x3))/n

mirror of cell (1,3) mirror of cell (2,3) ∑X32 - (∑x3)2/n

Now just invert and multiply by the y matrix to get your equation coefficients.

TJ

PS. These posts eliminate subscript and superscript, so I hope you can tell which is which. ∑X22 is the sum of x2 squared, etc. Email me if you want a readable pdf copy.