Quantcast
Channel: Intel® Software - Intel® oneAPI Math Kernel Library & Intel® Math Kernel Library
Viewing all articles
Browse latest Browse all 3005

Basic nth order curve fit

$
0
0

My goal: Using a small data set (3 - 40 points), calculate the coefficients of an n-th order polynomial, using either the MKL library, or IPP library that fits a data set using c++. Then from that equation, calculate its derivative and solve for any roots, using constraints. I suspect this is something easy, yet I have been searching and searching for just a basic code example and haven't really found what I'm looking for.

Here is a very basic example of such a problem that I solved using Excel trend lines.  Input data points x1, y1 (13, 14153.6), x2, y2 (14, 14155.79), x3, y3, (15, 13736.97).  First derive a 2nd order equation that roughly fits this data.  Excel spits back the trendline equation y = -210.5x^2 + 5685.7x - 24186.  So I would be looking for a code example (MKL, or IPP) that gives me the coefficients -210.5 and 5685.7 for this basic example.  From there I have a model of my data and I'm looking to interpolate a peak from these 3 points (which will probably be somewhere between 13 - 14).  This is a simple enough equation that I can calculate the derivative, set it equal to 0 and solve for x, which turns out to be 13.5052.  So I might be looking for a function that takes for its input the 3 data points (array), and what order of polynomial to fit for and then spits back the coefficients.

I can extend my example to 24 points (x = 1 - 24), y = {1700.347656, 2154.535156, 2760.722656, 3649.910156, 4886.097656, 6507.285156, 8244.472656, 10070.66016, 11762.84766, 13218.03516, 13872.22266, 14135.41016, 14153.59766, 14155.78516, 13736.97266, 12577.16016, 10917.34766, 9318.535156, 7739.722656, 6247.910156, 4968.097656, 3924.640625, 3086.183594, 2482.726563}.  Again using Excel, I can get a 6th order curve fit (or 2nd, or whatever I would like).  y = -0.0031x6 + 0.2293x5 - 5.6862x4 + 46.001x3 + 27.263x2 - 58.167x + 1766.  This is a bit trickier to calculate the roots of the derivative.  Using the Excel solver, i hand calculated an equation for the derivative, then used a constraint that my root had to be bigger than 10 (as I expect my peak to be around 13 somewhere).  The solution was 12.664.  

Hopefully this gives a flavor of what I would like to do.  Right now I'm lost in the sea of functions/examples and I'm just trying to get a basic example working.  I'm trying with the MKL data fit functions, but maybe those are more complex than I need.

 


Viewing all articles
Browse latest Browse all 3005

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>