Skip to main content
5-Regular Member
July 11, 2014
Solved

Get a best fit line from a function for system programing

  • July 11, 2014
  • 10 replies
  • 5958 views

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.

Best answer by RichardJ

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.

10 replies

23-Emerald I
July 12, 2014

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.

RichardJ19-TanzaniteAnswer
19-Tanzanite
July 14, 2014

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.

jroth5-Regular MemberAuthor
5-Regular Member
July 14, 2014

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.