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..

Syntax

nValue = CLsqFit:GetPolyCoefIndex( nIndex1, nIndex2, ... )

bullet.gif    nIndex1, etc. are indices for the polynomial dimension. Up to 10 indices are allowed.

Remarks

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.

Examples

The following script retrieves the number of dimensions used by the basis function being fit.

L = new_lsqfit()

-- create a CLsqFit object

L:SetNumCoefs( {5,3} )

-- Declare a 4x3 polynomial fit in 2 dimensions

n = L:GetPolyCoefIndex( 3, 2 )

-- fetch the index of 3, 2

Printf( "series = %d\n", n )

-- result: n = 8 ( element 3 in row 2 with row length 5)

n = L:GetPolyCoefIndex( 12, 4 )

-- fetch the index of 12, 4 (out of bounds)

Printf( "series = %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 = new_lsqfit()

-- create a CLsqFit object

L:SetNumCoefs( { 7, 3, 5 } )

-- Declare a 7x3x5 polynomial (7 cols, 3 rows, 5 planes)

n = L:GetPolyCoefIndex( 1, 2, 4 )

-- fetch the index of indices 1, 2, 4

Printf( "series = %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 = new_lsqfit()

-- create a CLsqFit object

L:SetNumCoefs( 9 )

-- Declare a 9 coef polynomial in 1 dimension

n = L:GetPolyCoefIndex( 6 )

-- fetch the index of index 6

Printf( "series = %d\n", n )

-- result: n = 6

Related Topics

CLsqFit class, SetNumCoefs, SetBasisFunc, GetCoef


Mira Pro x64 Script User's Guide, Copyright Ⓒ 2023 Mirametrics, Inc. All Rights Reserved.