1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Unable to find the nonlinear least squares

  1. Apr 4, 2009 #1
    1. The problem statement, all variables and given/known data
    We have the following x, y values
    x ||| y
    1.0 -0.15
    1.5 0.24
    2.0 0.68
    2.5 1.04
    3.0 1.21
    3.5 1.15
    4.0 0.86
    4.5 0.41
    5.0 -0.08

    How can you find the equation
    [tex]y(x) = ax^2 + bx + c[/tex]
    by least squares?

    3. The attempt at a solution
    I know how to calculate the equation for a line by solving
    Ax = b
    taking transposes of A at the both sides
    [tex]A^TAx = A^Tb[/tex]
    and then solving for x.

    My second attempt
    I made a 9 x 3 matrix for A where the first two columns are ones, 3 x 1 for x and 9 x 1 for b.
    However, I get a singular matrix for

    Apparently, my method is not right.

    I could make 3 equations such as
    y(0), y(1) and y(2)
    and solve for a, b and c.
    However, I see that the method is not least squares and also rather inaccurate, since
    not all points are considered.
    Last edited: Apr 4, 2009
  2. jcsd
  3. Apr 4, 2009 #2


    User Avatar
    Science Advisor

    To find [itex]y= ax^2+ bx+ c[/itex] that gives the best fit, the equation you are trying to solve is AX= Y:
    [tex]\begin{bmatrix}x_1^2 & x_1 & 1 \\ x_2^2 & x_2 & 1\\\cdot & \cdot & \cdot \\\cdot & \cdot & \cdot \\ \cdot & \cdot & \cdot \\ x_n^2 & x_n & 1\end{bmatrix}\begin{bmatrix} a \\ b \\ c\end{bmatrix}\begin{bmatrix}y_1 \\ y_2 \\\cdot \\\cdot\\\cdot \\ y_n\end{bmatrix}[/tex]
    Multiplying by the transpose of A on both sides gives an equation with a 3 by 3 matrix you can solve:

    [tex]\begin{bmatrix} \sum x_i^4 & \sum x_i^3 & \sum x_i^2 \\ \sum x_i^3 & \sum x_i^2 & \sum x_i \\ \sum x_i^2 & \sum x_i & n\end{bmatrix}\begin{bmatrix}a \\ b \\ c\end{bmatrix}= \begin{bmatrix} \sum x_i^2y_i \\ \sum x_iy_i \\ \sum y_i \end{bmatrix}[/tex]
  4. Apr 7, 2009 #3
    Let your columns to be A1, A2 and A3, respectively for the first, second and third columns.
    Is it wrong to write the columns as A3, A2, A1?

    I have always set the column with the lowest degree to be the first column, and
    so on.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook