×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Are you an
Engineering professional?
Join Eng-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Non-Linear Least Squares - Curve Fit2

## 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

### RE: Non-Linear Least Squares - Curve Fit

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

### RE: Non-Linear Least Squares - Curve Fit

(OP)
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

### RE: Non-Linear Least Squares - Curve Fit

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

### RE: Non-Linear Least Squares - Curve Fit

http://www.geocities.com/greglocock

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

2
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
http://www.aero.org/

### RE: Non-Linear Least Squares - Curve Fit

I knew there was a proper way of doing it. Thanks. What is the proper name for that technique, by the way?

Cheers

Greg Locock

### RE: Non-Linear Least Squares - Curve Fit

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
http://www.aero.org/

### RE: Non-Linear Least Squares - Curve Fit

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.

### RE: Non-Linear Least Squares - Curve Fit

if you post the points, i'll do the regression and submit several degreed equations on this site.

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

#### Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a partâ€™s function at the center of their design considerations. Download Now
Industry Perspective: Education and Metal 3D Printing
Metal 3D printing has rapidly emerged as a key technology in modern design and manufacturing, so itâ€™s critical educational institutions include it in their curricula to avoid leaving students at a disadvantage as they enter the workforce. Download Now

Close Box

# Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!