Cart | Help
 You are here: NI Home > NI Developer Zone > NI Discussion Forums Select Community English Français Italiano 日本語 한국어 Español 简体中文 繁体中文 Português (BR)

Member
Posts: 125

# How are coefficients returned when using the CWStat Polyfit function?

I am trying to extract the coefficients returned by the "Polyfit" function.

For example, I am trying to fit a 2nd order polynomial equation to a set of points. The Coef variant returns 3 values.

Which one is the coefficient for x2, x, and offset?

Thanks!

Member
Posts: 62

# Re: How are coefficients returned when using the CWStat Polyfit function?

Howdy Steverino -

Keeping the prototype in mind:
CWStat.PolyFit x, y, Order, z, Coef, mse

Coef is an output (variant type) of one-dimensional array of polynomial coefficients.

Therefore, the first element in Coef is your offset, second element in Coef is x, third element is x2.

For more information on the PolyFit function, as well as an example, consult the "Measurement Studio Reference" (usually found in Start Menu>>Program Files>>National Instruments>>Measurement Studio>>Help>>Measurement Studio Help).

Have a great day!

Andrew W || Applications Engineer
National Instruments

Member
Posts: 25

# Re: How are coefficients returned when using the CWStat Polyfit function?

Andrew,

Regarding your statement: "Therefore, the first element in Coef is your offset, second element in Coef is x, third element is x2."

I trust your information, but the order of returned coeficients does not follow from the prototype. And this does not seem to be documented anywhere, either in the Reference Manual or in the examples.

So, for an example, a PolyFit of order 3 (AX^3 + BX^2 + CX + D) returns the coefficients as:

coef[0] = D

coef[1] = C

coef[2] = B

coef[3] = A

Is this correct? It seeme very counter-intuitive!

Thanks!

Jesse