Unable to find the nonlinear least squares

Click For Summary
SUMMARY

The discussion focuses on solving the nonlinear least squares problem to fit a quadratic equation of the form y(x) = ax² + bx + c to a given set of x, y values. The correct approach involves constructing a design matrix A, where the first column contains x² values, the second column contains x values, and the third column contains ones. The user initially attempted to solve the problem using a singular matrix, which led to confusion. The proper method requires multiplying the transpose of A by itself and then solving the resulting normal equations to find the coefficients a, b, and c.

PREREQUISITES
  • Understanding of least squares regression
  • Familiarity with matrix operations, specifically transposes and multiplication
  • Knowledge of quadratic functions and their coefficients
  • Experience with solving linear equations
NEXT STEPS
  • Learn how to construct design matrices for polynomial regression
  • Study the derivation of normal equations in least squares fitting
  • Explore numerical methods for solving linear systems, such as LU decomposition
  • Investigate software tools like NumPy for implementing least squares solutions in Python
USEFUL FOR

Students and professionals in data analysis, statisticians, and anyone involved in mathematical modeling or regression analysis who seeks to understand and apply nonlinear least squares fitting techniques.

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
[tex]y(x) = ax^2 + bx + c[/tex]
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
[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
[tex]A^TA.[/tex]

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 [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]
 
HallsofIvy said:
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]

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

  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 25 ·
Replies
25
Views
9K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K