Interpretation of the var[8] coefficents stored by polyfit

Posted By: GPEngine

Interpretation of the var[8] coefficents stored by polyfit - 07/31/14 02:33

polyfit (var* coeff, vars Data, int TimePeriod, int order, var weight) : var
takes
"coeff A var[8] array for storing the calculated polynom coefficients,"
and modifies it

But what is the sense of the 8 values I wonder. My guess is that 0 is the y-intercept, 1 is the coefficient for the x term, 2 is the coefficient for the x^2 term, etc. Is that correct?
Can you please document this?
Posted By: jcl

Re: Interpretation of the var[8] coefficents stored by polyfit - 07/31/14 06:12

Yes, that is correct. For looking up the meaning of the mathematical terms in the manual, Wikipedia is a good source. There you'll often also find the algorithms.
Posted By: GPEngine

Re: Interpretation of the var[8] coefficents stored by polyfit - 08/01/14 03:42

Wikipedia will not tell you what order your polyfit method populates the coeff array .
Posted By: jcl

Re: Interpretation of the var[8] coefficents stored by polyfit - 08/01/14 06:34

Ah, I see. It is populated from the start.
Posted By: GPEngine

Re: Interpretation of the var[8] coefficents stored by polyfit - 08/01/14 14:19

confused
no, i mean the order of the coefficients in the output array is a design choice that is not stated in the manual. It took some experiments, but I figured out that it is implemented like this:
1. the value of coeff[n] gets the coefficient for the x^n term.
2. for polyfits with degree < m, coeff[m] through coeff[8] are 0.

I'm just trying to help the next person save a few steps here.


I have a related observation about something tricky.
The independent variable, x, for the polyfit is the bar index. 0 is the current bar, and the sense of it is that bar index decreases with time. Therefore, the first coefficient which is commonly thought of as the slope, or m, will actually be negative for rising series.
© 2024 lite-C Forums