Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

Help Using Polyfit function Please

Hi,
I am using Measurement Studio 6 and am struggling to solve a problem using the Polyfit function.

Basically I have an array containing x and y values of a set of resistances taken. The x contains the number of seconds after I switch a motor off and the y contains the resistance values of a field coil.
I am measuring a hot field coil resistance whilst it is cooling.
For example I may start measuring the resistance after 20 seconds and continue to measure for 2 minutes.
I then want to polyfit these resistance readings to calculate the resistance at x = 0 i.e at switchoff. My first reading would be x = 20 but I need to fit back to 0

I would really appreciate any help on this.

Many thanks.
0 Kudos
Message 1 of 5
(4,514 Views)
The polyfit function gives you coefficients of a function of the following form: f(x)= A(0) + A(1)*x...A(n)*x^n. Obviously, the more datapoints you have then the more coefficient you may be allowed to use. However, you may find that extrapolating the function outside the range of data may give suprising results. This is due to the nature of the mathematics. The best to fit any natural phenomenon is to find out what kind of curve is to be expected and to try to find a mathematical model that best fits the phenomenon.
Joji
0 Kudos
Message 2 of 5
(4,514 Views)
Thanks for the comments. I should have explained myself a bit clearer.
I will be using a 3rd order polynomial. and have approximately 100 readings which allow a good curve fit.
Would the polyinterp function do this better ?
I guess in summary I am extrapolating back to zero from readings taken from 30secs to 120 secs and need a 3rd order polynomial fit.
Many thanks
0 Kudos
Message 3 of 5
(4,514 Views)
If you have confidence that the curve represented by the Polyfit function is representative of the "real" behavior of the phenomenon outside the range of the acquired datapoints, then just calculate the function at f(x=0). The polyinterp function would, I believe, behave better within the range of the datapoints but may behave badly outside the range.
Joji
0 Kudos
Message 4 of 5
(4,514 Views)
Thanks again.
It seems my programming skills are not upto scratch !

I am using the code below

x = Array(10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)
y = Array(9.9, 9.7, 9.5, 9.3, 9.1, 8.9, 8.7, 8.6, 8.5, 8.45, 8.4)

order = 3
'x input time in sec's of first reading
'y input resistance recorded
'z output of best fit
CWStat1.PolyFit x, y, order, z, coef, mse

For example I have recorded my first resistance reading of 9.9 Ohms ater 10 secs and then recorded further readings for a total time of 20secs.

Can you help with example code for this please ?
i.e to use a 3rd order polynomial to calculate resistance at zero.

Many thanks again.
0 Kudos
Message 5 of 5
(4,514 Views)