Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perform a Least Squares Curve Fit 2

Status
Not open for further replies.

wzal

Mechanical
Mar 18, 2004
35
Hi, everyone,

I am trying to find a program to perform a least squares curve fit with a ten coefficient equation.

z=c1+c2*(x)+c3*(y)+c4*(x^2)+c5*(x*y)+c6(y^2)+c7*(x^3)+c8(x^2*y)+c9(x*y^2)+c10*(y^3)

Does anyone know where I could find the program?

Thanks in advance.
 
Replies continue below

Recommended for you

My starting point would be Excel. Set up your data in a table. Make a starting guess at your ten coefficients, placing them in ten adjacent cells on the spreadsheet. Add the resulting z-prediction in another column in your table. In yet another column place the square of the difference between the z-actual and the z-prediction. At the bottom of that column put the sum of all the squared "errors".

Now use the Solver which comes as a standard part of Excel. (You may need to activate its add-in first.) You want to minimise the sum of the squared errors by varying your ten coefficients. Your answer is then one click away, since your problem is (presumably) an unconstrained one.

Two caveats. Firstly I have never used the Solver with as many as ten variables, so I cannot vouch for it here. Secondly, you need your starting guess to be reasonably close to the final answer.

HTH
 
wzal, how many data points do you have? I'd certainly do it in Excel.



Cheers

Greg Locock
 
I suppose that you would like to fit some property z=f(x,y)in form of a polynomial of a third degree including mixed terms.Use Excel and write z's in the first column, x's in the second, y's in the third. Now form the fourth column where you write the result of x^2, in the fifth the result of y^2,then x^3 in the next and so on until you have all combinations of x's and y's, each in its own column.
Now make make linear fit and select the non-zero range of all columns but the first one as independent variables and let Excel calculate the coefficients.
Try first with a simple case with z=Ax+By+Cxy to see the idea.
m777182
 
I do a lot of this sort of thing and I do it exactly the way m777182 recommended.

I have tried dedicated programs, and never found anything that matches a spreadsheet - I use Excel and Quattro Pro. A useful advantage of doing it in a spreadsheet is that you can link a graph to the results and immediately see how good your curve is.
 
I have written a program in basic which takes a set of coordinte pairs and produces an equation/graph of best fitting curve. It is on an old set of IBM punch cards.
 
WZAL, WHERE IS YOUR EQUATION APPLIED? ALSO,CAN IT BE SIMPLIFIED SO THAT A 2D REGRESSION ANALYSIS CAN BE USED?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor