Results 1 to 2 of 2

Math Help - Least squares to matrix to poly coefficients

  1. #1
    Newbie
    Joined
    Dec 2012
    From
    Oregon
    Posts
    2

    Smile 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 x1 x2 x3 y
    覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧
    1
    2

    29
    覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧覧




    x2 and x3 have the form:


    x2 = x1^2
    x3 = x1^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 = ∑X2 - (∑x)2/n This is for cells (1,1), (2,2) and (3,3), using x1, x2 and x3 respectively.


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


    SP = ∑(x1*x2) - ((∑x1)(∑x2))/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:




    ∑X12 - (∑x1)2/n
    ∑(x1*x2)-((∑x1)(∑x2))/n
    ???
    mirror of cell (1,2)
    ∑X22 - (∑x2)2/n
    ???
    mirror of cell (1,3)
    mirror of cell (2,3)
    ∑X32 - (∑x3)2/n




    The question marks are where I知 stumped. This procedure works great for a 2x2 matrix and a 2nd degree polynomial. But now I知 expanding to a 3x3 matrix for a 3rd degree polynomial. I致e tried every combo of SP痴 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
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Newbie
    Joined
    Dec 2012
    From
    Oregon
    Posts
    2

    Re: Least squares to matrix to poly coefficients

    Murphy痴 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.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 1
    Last Post: September 21st 2011, 07:31 AM
  2. min poly = char poly
    Posted in the Advanced Algebra Forum
    Replies: 7
    Last Post: May 26th 2010, 08:30 AM
  3. Replies: 4
    Last Post: November 13th 2009, 05:12 PM
  4. sum of squares and covariance matrix
    Posted in the Advanced Statistics Forum
    Replies: 0
    Last Post: November 4th 2009, 05:19 AM
  5. Replies: 1
    Last Post: January 16th 2009, 09:07 PM

Search Tags


/mathhelpforum @mathhelpforum