# Homework Help: Unable to find the nonlinear least squares

1. Apr 4, 2009

### soopo

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
$$y(x) = ax^2 + bx + c$$
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
$$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: Apr 4, 2009
2. Apr 4, 2009

### HallsofIvy

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}$$

3. Apr 7, 2009

### soopo

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.