Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X
Hello,
I am looking at trying to get a best fit curve line, say a quadratic to the data function at the bottom of document. My intent is to program in the dP(m) for the most part, disregarding the temperature and the pressure as those don't have a drastic effect on the curve considering my dP meter is from 0 to 20" of water. (about 3% at most)
I was unsure if there is a simple way in mathcad rather than finding 3 pionts and setting my data to those 3 points for a best fit, to use the gen fit to find the coefficients.
Solved! Go to Solution.
What you want to do is called functional approximation. There are many methods for doing this, but a good one is an approximation based on Chebyshev polynomials. I have attached two worksheets. One explains the math behind Chebshev functional approximation. It is obviously from a handbook, but I can't figure out which one it comes from (I saved it as a separate worksheet years ago). The second shows the implementation for your example. That worksheet also includes a stand-alone function I wrote to do all the necessary steps. It takes the polynomial degree, the name of the function, and the interval for the approximation as inputs, and returns the coefficients of the approximating polynomial.
The function "regress" will do a least square polynomial fit. If you use only three points, a second order ploynomial will fit those three points but may not approximate the curve correctly. Build vectors of many points, use regress, and plot the errors to choose the correct order of the polynomial.
What you want to do is called functional approximation. There are many methods for doing this, but a good one is an approximation based on Chebyshev polynomials. I have attached two worksheets. One explains the math behind Chebshev functional approximation. It is obviously from a handbook, but I can't figure out which one it comes from (I saved it as a separate worksheet years ago). The second shows the implementation for your example. That worksheet also includes a stand-alone function I wrote to do all the necessary steps. It takes the polynomial degree, the name of the function, and the interval for the approximation as inputs, and returns the coefficients of the approximating polynomial.
Richard,
That is quite amazing and exactly what I was looking for. I will have to look more into the Chebyshev Polynomials and see what else I can apply them to.
Richard,
Do you have a Prime2 or earlier mathad version of these (at least the general sheet from the workbook) that you can post?
Lou
Here's the worksheet in MC15 and MC11 formats. The self contained function is added near the end. In MC11 it's not quite self contained, as it needs two helper functions.
Thanks. I'm familiar with equiripple filters using Chebychev approximations. I see that this technique is a more general method of getting optimal equiripple error approximations to functions (instead of min mean square error); useful in cases where the peak error bound is more critical than the error "energy."
Lou
Yes, it minimizes the maximum error, rather than the least squares error. Well, almost anyway. The polynomial is an approximation to the polynomial that minimizes the maximum error. Ther more terms, the better the approximation.
This describes exactly how that is achieved:
http://www-solar.mcs.st-and.ac.uk/~clare/Lectures/num-analysis/Numan_chap3.pdf
http://www-solar.mcs.st-and.ac.uk/~clare/Lectures/num-analysis/Numan_chap4.pdf
Richard,
The PDFs you linked, are they out of a numerical analysis book? If so, could you provide the title. I would be interested in picking up a book in that area as my libaray is somewhat lacking in numerical methods.
They are from here: http://www-solar.mcs.st-and.ac.uk/~clare/Lectures/num-analysis.html
Richard,
Thank you. The lectures are helpful. I have done a B Cubic Spline fit where I have extracted the derivative of my curved data. Attached is a PDF showing the results.
As a side note, I have actually coded the process in MathCad 15 to plow through the data accuratly using VBA code. All I do is feed it the vector form of the data, and it will send back the new derivative data vector as I want.