Monday, January 6, 2014

Polynomial curve fit PolyFit and PolyFits in Excel

PolyFit allows you to curve fit two sets of data into a polynomial formula and gives you the answer given the new variable. It is very flexible and it allows you specify your own polynomial power order. PolyFits allows you to fit your data into several segments of polynomial formulas.


The problem
Curve fitting is a common task for engineers. Polynomial curve fitting is the most convenient one. You can first plot out your data in Excel, format trend line using polynomials and then display equation on chart to get the coefficients. Finally you manually type the coefficients into excel and manually write the equation to calculate the new y corresponding to a new x.

The above method works, but it is not efficient and it is easy to make mistakes. Especially if your raw data changes, you will need to repeat the same steps manually again. Engineers are smart and engineers should be doing something more creative. Isn't it?

The solution
As a certified programmer with engineering background, I wrote a program to quickly do the task above. Simply give me the raw data set and the new x, you get your new y within a second.

In this example, DB is the "known_Xs" and Output is the "known_Ys", given the newx of 30, in cell of E7, you simply type the formula as in the picture, instantly you get the newy of 1.0383.

In addition, the PolyFit function also returns R2, coefficients and the formula.

What's more, sometimes, one curve might not be able to fit all your raw data, then you need to fit all the raw data into two or more curves. This is where PolyFitS can help. After you download the excel file, you can find more information about PolyFitS.


To download the excel file, please join the "Computer Programming Tips for Engineers, Half Effort, Double Productivity" Group on LinkedIn or started a new discussion in that group. Click to find more https://www.linkedin.com/groups/Computer-Programming-Tips-Engineers-Half-8325117/about