CLsqFit:GetNumCoefs


The GetNumCoefs method returns the number of coefficients used in the fit or the number of coefficients used in the n-th dimension of the n-dimensional polynomial fit.

Syntax

CLsqFit:GetNumCoefs()

CLsqFit:GetNumCoefs( nDimension )

bullet.gif    nDimension specifies the dimension for a multi-dimensional fit.

Remarks

This method returns a value between 1 and the total number of coefficients set by the SetNumCoefs method. Depending on the basis function being used, the return value is as follows:

Fitting an n-dimensional polynomial

GetNumCoefs() returns either the total number of coefficients being fit or the number of coefficients used in the n-th dimension. For example, if the script calls SetNumCoefs( {5, 3} ), then GetNumCoefs() returns 15 (=5x3). For the same setup, GetNumCoefs(1) returns the number of coefficients in dimension 1, which is 5, and GetNumCoefs(2) returns the number of coefficients in dimension 2, which is 3. For dimensions higher than that specified for the polynomial, GetNumCoefs(n) always returns 1.

Hyperplane

GetNumCoefs() returns the number of coefficients fit by the hyperplane, which includes 1 coefficient for a constant term. For example, if the fit uses the hyperplane and sets SetNumCoefs(6), GetNumCoefs() returns 6, but GetNumCoefs(2) returns 1.

Fitting a user-specified basis function

GetNumCoefs() returns the number of coefficients used by the basis function. For example, if the basis function fits 7 coefficients to 3 dimensions using SetNumCoefs(7,3), then the dimension argument is disregarded and GetNumCoefs() returns 7.

Examples

The first example, below, defaults to fitting the built-in n-dimensional polynomial. This script specifies 3 coefficients for fitting a 2nd order polynomial to 1 variable. Since only 1 argument is specified, the polynomial fits 1 independent variable.

L = new_lsqfit()

-- create a CLsqFit object

L:SetNumCoefs( {3, 5} )

-- set 3x5 coefficients for the n-dimensional polynomial

n = L:GetNumCoefs()

-- return the number of coefficients

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

-- result: n= 15

n = L:GetNumCoefs(1)

-- return the number of coefficients in dimension 1

Printf( "n[%d] = %d\n", 1, n )

-- result: n[1] = 3

n = L:GetNumCoefs(2)

-- return the number of coefficients in dimension 2

Printf( "n[%d] = %d\n", 2, n )

-- result: n[2] = 5

 

The next example used a basis function defined in the script (not the built-in n-Dimensional Polynomial). For this case, GetNumCoefs returns the number of coefficients set by the SetNumCoefs method:

L = new_lsqfit()

-- create a CLsqFit object

L:SetBasisFunc( "F" )

-- specify a basis function named "F"

L:SetNumCoefs( 9, 5 )

-- set 9 coefficients and 5 independent variables

n = L:GetNumCoefs()

-- return the number of coefficients

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

-- result: nCoefs = 9

Related Topics

CLsqFit class, Using Multiple Independent Variables, Basis Functions, SetNumCoefs, SetBasisFunc, GetBasisDim


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