CLsqFit:GetBasisDim


The GetBasisDim method returns the number of dimensions of independent variable. This value was set using the SetNumCoefs method.

Syntax

nDim = CLsqFit:GetBasisDim()

where

    nDim is a number between 1 and 10.

  

This function returns the number of independent variables used in the fit. This equals the dimension of the basis. The sample points must be added with data for the corresponding number of dimensions as shown in AddPt and AddPtWt.

Examples

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

L = CLsqFit:new()

-- create a CLsqFit object

 

-- no function declared, n-dimensional polynomial (1) used

L:SetNumCoefs( {2,2} )

-- Declare a 2x2 coefficient fit

nDim = L:GetBasisDim()

-- fetch the number of basis dimensions

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

-- result: Dim = 2

The next example defines a basis function in the script and registers it, The basis function fits 2 coefficients to one independent variable (i.e., 1 dimension). The script then fetches the basis function properties.

function MyFunc( n, c )

-- declare a basis function

  b = {}

 

  b[1] = 1

 

  b[2] = c[1]

 

  return b

 

end

-- end of basis function

L = CLsqFit:new()

-- create a CLsqFit object

L:SetBasisFunc( "MyFunc" )

-- register the basis function

L:SetNumCoefs( 2 )

-- fit 2 coefficients in 1 dimension

s = L:GetBasisFunc()

 

nDim = L:GetBasisDim()

-- fetch the number of basis dimensions

Printf( "Dim '%s'= %d\n", s, nDim )

-- result: Dim 'MyFunc' = 1

Related Topics

SetNumCoefs

SetBasisFunc

GetBasisFunc

CLsqFit Class