CLsqFit:GetPolyCoefIndex
The GetPolyCoefIndex method converts the n-th dimension polynomial coefficient index to a single index in the coefficient table. Use this method with the n-dimensional polynomial basis function when the number of basis dimensions is higher than 1. Then the polynomial dimension is greater than 1, this method is needed for getting the index to pass to GetCoef, GetCoefErr, ForceCoef, and other methods since they accept only a single index argument..
nValue = CLsqFit:GetPolyCoefIndex( nIndex1, nIndex2, ... ) |
This function converts the n-dimensional polynomial coefficient index into a single value. The polynomial coefficients are stored in a table based on a hierarchy where the first index is the most rapidly varying index, the second index is second most rapidly varying, and so on. For example, if fitting 5 x 3 coefficients to a 2-dimensional polynomial, the coefficients are stored in 3 rows of 5 values. This method does not check that each dimensional index is within bounds, but rather only that the final result is in the range defined by the limits 1 and GetNumCoefs().
The following script retrieves the number of dimensions used by the basis function being fit.
L = CLsqFit:new() |
-- create a CLsqFit object |
L:SetNumCoefs( {5,3} ) |
-- Declare a 4x3 polynomial fit in 2 dimensions |
|
-- fetch the index of 3, 2 |
Printf( "Index = %d\n", n ) |
-- result: n = 8 ( element 3 in row 2 with row length 5) |
|
-- fetch the index of 12, 4 (out of bounds) |
Printf( "Index = %d\n", n ) |
-- result: n = 6 (out of bounds returns 1 or max index) |
The next script sets a polynomial fit of 3 dimensions and retrieves the index of a point:
L = CLsqFit:new() |
-- create a CLsqFit object |
L:SetNumCoefs( { 7, 3, 5 } ) |
-- Declare a 7x3x5 polynomial (7 columns, 3 rows, 5 planes) |
|
-- fetch the index of indices 1, 2, 4 |
Printf( "Index = %d\n", n ) |
-- result: n = 71 (column 1 in row 2 in plane 4) |
The final script sets a polynomial of 1 dimension and retrieves the index of a point: In this case, calling GetPolyCoefIndex returns the same index as is passed as an argument:
L = CLsqFit:new() |
-- create a CLsqFit object |
L:SetNumCoefs( 9 ) |
-- Declare a 9 coef polynomial in 1 dimension |
|
-- fetch the index of index 6 |
Printf( "Index = %d\n", n ) |
-- result: n = 6 |