Non-Linear Least Squares - Curve Fit
Non-Linear Least Squares - Curve Fit
(OP)
How can I do a simple non linear least squares regression on a few data points inorder to find the inflection point?
The data resembles a second order polynomial, a parabola. I have about 3-4 points and need only an approxmate answer.
I figure I can do a simple polymonial least squrares regression analyis to determine the best fit quadratic equation through the line. Then I would take the differential of this equation and solve for the inflection poing - zero, ie the bottem (or top of the parabola).
I am programing in Fortran 77, however I can convert. BTW I need to do this 1.6 million times.
Thanks,
Harry
The data resembles a second order polynomial, a parabola. I have about 3-4 points and need only an approxmate answer.
I figure I can do a simple polymonial least squrares regression analyis to determine the best fit quadratic equation through the line. Then I would take the differential of this equation and solve for the inflection poing - zero, ie the bottem (or top of the parabola).
I am programing in Fortran 77, however I can convert. BTW I need to do this 1.6 million times.
Thanks,
Harry





RE: Non-Linear Least Squares - Curve Fit
However, if you only have 3 points then you don't need a least squares fit, you will get an analytical solution. With 4 points you could do something horrible like fitting each subset of 3 points and averaging the resulting coefficients.
Cheers
Greg Locock
RE: Non-Linear Least Squares - Curve Fit
When you say use an analytical method for 3 points, do you mean to assume it is a parabolic curve and just plug the values into something like y = ax^2 + bx + c ? I say this because I don't know the I don't know the form of the curve.
I think (for data points where x is close to the inflection point) it could be represented by
(y-c) = a(x-b)^2
where (b,c) would be the inflection point (lowest point on the parabola), and 'a' would describe the steepness of the parabola (and is always positive in my situation).
Actually c is the value I am looking for. It is the lowest point on the parabola. If I used only three points, would I solve this with a matrix of three simultaneous equations? I am a bit rusty on this.
Harry
RE: Non-Linear Least Squares - Curve Fit
just expand your equation out, substitute your x and y pairs in, to give three simulataneous equations then eliminate a and b. You may find it easier to solve for a and b first, and then find c. Or you can solve the matrix, it is all one.
Just looking at it, your formulation of it makes it harder to solve, you may want to solve the ax^2+bx+c formulation and then recast it into your notation.
Cheers
Greg Locock
RE: Non-Linear Least Squares - Curve Fit
go to the gallery
second entry is the analytical solution of a parabola in standard formulation, from 3 x,y pairs
Your preferred formulation is just as solvable, but the expression for c is two or three screen widths wide, so rather difficult to display.
Cheers
Greg Locock
RE: Non-Linear Least Squares - Curve Fit
P=Sum(x)
Q=Sum(x^2)
R=Sum(x^3)
S=Sum(x^4)
T=Sum(y)
U=Sum(xy)
V=Sum(x^2y)
W=N*Q*S+2*P*Q*R-Q^3-P^2*S-N*R^2
Then
a=(N*Q*V+P*R*T+P*Q*U-Q^2*T-P^2*V-N*R*U)/W
b=(N*S*U+P*Q*V+Q*R*T-Q^2*U-P*S*T-N*R*V)/W
c=(Q*S*T+Q*R*U+P*R*V-Q^2*V-P*S*U-R^2*T)/W
That is a bit of a long answer, but if you have multiple uncertain points, it will generate the least squares fit. I have coded it in VBA, but Fortran should be snap also.
Brian Lewis
The Aerospace Corporation
http://www.aero.org/
RE: Non-Linear Least Squares - Curve Fit
Cheers
Greg Locock
RE: Non-Linear Least Squares - Curve Fit
Brian Lewis
The Aerospace Corporation
http://www.aero.org/
RE: Non-Linear Least Squares - Curve Fit
The built-in fregression routines include:
CubicReg Cubic regression — Fits the data to the third-order polynomial y=axò +bxñ +cx+d. You must have at least four data points.
- For four points, the equation is a polynomial fit.
- For five or more points, it is a polynomial regression.
ExpReg Exponential regression — Fits the data to the model equation y=abõ (where a is the y-intercept) using a leastsquares fit and transformed values x and ln(y).
LinReg Linear regression — Fits the data to the model y=ax+b (where a is the slope, and b is the y-intercept) using a least-squares fit and x and y.
LnReg Logarithmic regression — Fits the data to the model equation y=a+b ln(x) using a least-squares fit and transformed values ln(x) and y.
Logistic Logistic regression — Fits the data to the model y=a/(1+b*e^(c*x))+d and updates all the system statistics variables.
MedMed Median-Median — Fits the data to the model y=ax+b (where a is the slope, and b is the y-intercept) using the median-median line, which is part of the resistant line
technique.
PowerReg Power regression — Fits the data to the model equation y=axb using a least-squares fit and transformed values ln(x) and ln(y).
QuadReg Quadratic regression — Fits the data to the secondorder polynomial y=axñ +bx+c. You must have at least three data points.
- For three points, the equation is a polynomial fit.
- For four or more points, it is a polynomial regression.
QuartReg Quartic regression — Fits the data to the fourth-order polynomial y=ax4+bxò +cxñ + dx+e. You must have at least five data points.
- For five points, the equation is a polynomial fit.
- For six or more points, it is a polynomial regression.
SinReg Sinusoidal regression — Calculates the sinusoidal regression and updates all the system statistics variables. The output is always in radians, regardless of the angle mode setting.
RE: Non-Linear Least Squares - Curve Fit