LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Ployfit Function Limitations

I'm trying to determine the polynomial equation for a dataset captured during a calibration procedure. I've eventually managed to get the polyfit function working by scaling the X axis data and the Y axis data to range from -1 to 1, as described in the documentation. If I don't use scaling I'm limited to using a sixth order polyfit on the specific dataset. With scaling I can go up to an 18'th order fit that can solve my positioning error to satisfaction. My problem however is that the coefficients will be totally wrong now and in this case simply multiplying them by the scaling factor will not fix my coefficient values.

Is there any way to get around this problem or maybe using a different function to determine the coefficients?

Jatti
e van der Linde
Software and System Integration Engineer
Magnetic Solutions Ltd
Unit 13, IDA Centre
Pearse Street
Dublin 2
Ireland

URL: http://www.magnetic-solutions.com
E-Mail: jvanderlinde@magnetic-solutions.com
Tel: +353(1) 670 4046
Fax: +353(1) 670 4047
Jattie van der Linde
Engineering Manager, Software & Automation
TEL Magnetic Solutions Ltd
0 Kudos
Message 1 of 3
(3,278 Views)
You should be able to multiply simply by the scaling factor if you followed all of the text correctly. It was:

If the elements in x are large and order is also large, you might see unstable results. One solution is to scale the input data elements to the range [—1:1]. To do this, perform the following steps:

Find the number, for example, k, in x that has the largest magnitude, or absolute value.

Divide all elements in the array by the absolute value of k.

Apply Polyfit and rescale the results in the output array by multiplying all elements in the output array by the absolute value of k.

This should allow you to simply multiply back to the coefficients the scaling factor to get the correct fit. You mentioned that you could go all the way to an 18
th term. Then what? If you are still seeing this error, please send us a demonstartion of what you are seeing. Thanks.
0 Kudos
Message 2 of 3
(3,278 Views)
Rescaling the elements in x allows me to go to an 18'th order polynomial, and multiplying the results by scaling factor (k)also works out correct. I am not interested in the result however. I want to determine the coefficients. By using my sample dataset and scaling the large x values I get a set of polynomial values. Using the same dataset and not scaling the x values I get a diffirent set of polynomial values. Plotting the calculated results give me exactly the same resulting fit.
Coefficient without scaling:

Coefficient 0: -1.9910e+000
Coefficient 1: 5.3458e-003
Coefficient 2: -4.8563e-006
Coefficient 3: -1.3094e-008
Coefficient 4: 1.6776e-011
Coefficient 5: 8.5927e-015
Coefficient 6: -8.6098e-018

Scaled Coefficients: (Multipl
ied by the scaling Factor of 1041)

Coefficient 0: -2.0734e+003
Coefficient 1: 5.7932e+003
Coefficient 2: -5.4785e+003
Coefficient 3: -1.5377e+004
Coefficient 4: 2.0512e+004
Coefficient 5: 1.0889e+004
Coefficient 6: -1.2909e+004

This proofs that I can not simply multiply the coefficients by the scaling factor and I've verified my results using Matlab. Attached see the dataset that I've used.

May aim is to achieve an 18'th order fit. The fitting works fine for any order size after scaling.
Jattie van der Linde
Engineering Manager, Software & Automation
TEL Magnetic Solutions Ltd
Download All
0 Kudos
Message 3 of 3
(3,278 Views)