09-08-2009 01:25 AM
I am using 30 day eval version of Measurement Studio . The problem is that I am getting different output from the matlab polyfit. I am using PolynomialFit function.
I am giving the following input -
Dim xData() As Double = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0} Dim yData() As Double = {1.0, 2.7, 7.4, 150.0, 80.0, 220.0} Dim temp() As Double = NationalInstruments.Analysis.Math.CurveFit.PolynomialFit(xData, yData, 3, NationalInstruments.Analysis.Math.PolynomialFitAlgorithm.LU)
And getting the following output-
-4.2809523809519066 8.55476190476141 36.790476190475822 79.509523809524 135.79523809523855 204.73095238095217
Where matlab code produces the following output -
-0.15278 8.15833 4.83016 -4.28095
Also the length of the output is equal to the input lent where as it should be =order + 1.
Thanks,
Arnab
09-08-2009 10:43 AM
Hello Arnab -
The output you are seeing is the fitted data. If you would like to get the coefficients back, you should use one of the overloaded methods that contains the output parameter coefficients. Once you do this, your coefficients should match up.
Please let us know if you have any more questions.
NickB
National Instruments
09-10-2009 06:56 AM
Nick,
Thanks for your help.Can you give me a sample code using the overloaded methods that contains the output parameter coefficients ?
Thanks,
Arnab
09-10-2009 09:24 AM
Hey Arnab,
No problem - here's a short snippet, let me know if you have any further questions:
Just for future reference, we do have code snippets for most of our analysis methods in our documentation. In this case, the most complex overload
has the code snippet. I've found that the easiest way to find this documentation is to use the index to search for the method name in question. This will bring up a page of all the available overloads, and generally the most complex overload will have a snippet for your inspection.
NickB
National Instruments
09-11-2009 03:09 AM
Nick,
Thanks a lot for your help.I now get my required coefficient.
Thanks,
Arnab