Unable to find the nonlinear least squares

AI Thread Summary
To find the best-fit quadratic equation y(x) = ax^2 + bx + c using least squares, the correct approach involves constructing a matrix A with columns representing x^2, x, and a constant term. The method requires solving the normal equations derived from multiplying the transpose of A by A and then by the vector of y values. Issues arise when the matrix A^TA is singular, indicating a problem with the matrix setup or data points. It is essential to maintain the correct order of columns in matrix A, typically starting with the highest degree term. Properly applying these steps will yield the desired coefficients a, b, and c for the quadratic fit.
soopo
Messages
222
Reaction score
0

Homework Statement


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
y(x) = ax^2 + bx + c
by least squares?

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
A^TAx = A^Tb
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
A^TA.

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:
Physics news on Phys.org
To find y= ax^2+ bx+ c that gives the best fit, the equation you are trying to solve is AX= Y:
\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}
Multiplying by the transpose of A on both sides gives an equation with a 3 by 3 matrix you can solve:

\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}
 
HallsofIvy said:
To find y= ax^2+ bx+ c that gives the best fit, the equation you are trying to solve is AX= Y:
\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}

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.
 

Similar threads

Back
Top