Minimizing square of deviation / curve fitting

Click For Summary
SUMMARY

This discussion focuses on fitting a quadratic curve, represented by the equation y=bx²+a, to a dataset (x,y) by minimizing the square of the deviation. The deviation for each data point is defined as d_i²=(y_i-y)²=(y-bx_i²-a)². The user successfully derives a system of equations by differentiating the sum of deviations and discusses the implementation of Cramer's Rule, LU decomposition, or Gaussian elimination (GE) to solve the resulting 2x2 system for the coefficients a and b. The discussion emphasizes that with approximately 300 data points, Cramer's Rule is the simplest method for this task.

PREREQUISITES
  • Understanding of quadratic functions and curve fitting
  • Familiarity with matrix operations and systems of equations
  • Knowledge of Cramer's Rule, LU decomposition, and Gaussian elimination
  • Basic proficiency in using spreadsheets for calculations
NEXT STEPS
  • Implement curve fitting using Python's NumPy library
  • Explore the efficiency of LU decomposition compared to Cramer's Rule
  • Learn about least squares regression techniques
  • Investigate advanced curve fitting methods such as polynomial regression
USEFUL FOR

Data scientists, statisticians, and anyone involved in mathematical modeling or data analysis who seeks to understand curve fitting techniques and their computational methods.

exmachina
Messages
42
Reaction score
0

Homework Statement



Given some data set, (x,y), fit to the the curve [tex]y=bx^2+a[/tex] by minimizing the square of the deviation. Preferred to use matrices.

Homework Equations


The deviation for the ith data point is simply:

[tex]d_i^2=(y_i-y)^2=(y-bx_i^2-a)^2[/tex]

The Attempt at a Solution



If I understand correctly, I want to minimize [tex]\sum{d_i^2}[/tex] by differentiating wrt to a and b and setting to zero to find the local minima. So far I have differentiated to yield the following system of equations:

[tex]\sum_{i}^n y_i = an + \sum_{i}^n bx_i^2[/tex]

[tex]\sum_{i}^n{x_i^2y_i}=a\sum_{i}^n x_i^2 + b \sum_{i}^n x_n^4[/tex]So I'm stuck using either Cramer's Rule, LU, or GE. Cramer's Rule is the easiest to implement, but I don't know how much slower it will be compared to LU/GE. I have around 300 data points
 
Last edited:
Physics news on Phys.org
It doesn't really matter what method you use, there are only two unknowns, a and b. It's a 2x2 system. Once you have found the summations of the various powers of your data points, it's easy.
 
Solving the system using Cramer's rule is very simple.

[tex]a = \frac { \sum x^{4}_{i} \sum y_{i} - \sum x^{2}_{i} \sum x^{2}_{i} y_{i}} {n \sum x^{4}_{i }- ( \sum x^{2}_{i})^2}[/tex]


[tex]b = \frac { n \sum x^{2}_{i} y_{i} - \sum x^{2}_{i} \sum y_{i}} {n \sum x^{4}_{i }- ( \sum x^{2}_{i})^2}[/tex]

and then calculate the sums using a spreadsheet
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
4K
Replies
2
Views
2K
  • · Replies 11 ·
Replies
11
Views
1K
  • · Replies 26 ·
Replies
26
Views
3K
Replies
6
Views
2K
  • · Replies 42 ·
2
Replies
42
Views
6K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K