Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Non-Linear Least Squares - Curve Fit 2

Status
Not open for further replies.

androsnich

Civil/Environmental
May 7, 2003
12
0
0
US
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
 
Replies continue below

Recommended for you

I know there is a proper answer to this, but can't remember how to do it.

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
 
Greg

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
 
Yes, if it is a parabola you can directly back solve for the parameters. I have got this in excel for the case y=ax^2+bx+c where one of the three pairs is (c,0), it is quite easy to work it out, just by back substitution.

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
 
If you have a set of multiple points (Not three exactly) and want to draw the best quadratic function y=ax^2+bx+c that best fits multiple points, calculate the following:

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
 
Not sure if there is a name for it. I got the technique from the book Astronomical Algorithms by Jean Meeus. His reference lists something thats long and in German, which I don't speak very well. A mathematician might know of the proper name for it.

Brian Lewis
The Aerospace Corporation
 
I know that this does not answer your question directly, but the Graphing Calculators by Texas Instruemnets, such as the TI-83,84, 86, 89 have several built in regession routines. I am assuming that the HP and Casio graohing calculators have the same built in function.

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.


 
Status
Not open for further replies.
Back
Top