CLsqFit:ResetPoints CLsqFit:SetNumChannels

CLsqFit:SetBasisFunc


The SetBasisFunc method selects the basis function to use for the fit. This function either selects one of the two built-in basis functions or specifies the name of a user-defined function declared in a script. Before writing a custom, user-defined, basis function, read the Basis Functions topic.

Syntax

CLsqFit:SetBasisFunc( sBasisFuncChoice )

bullet.gif    sBasisFuncChoice is the name of a built-in basis function.

bullet.gif    sBasisFuncChoice is a string giving the name of a user-provided function declared in a script.

Remarks

The value of sBasisFuncChoice is a string interpreted as follows:

"polynomial"

The built-in (default) n-dimensional polynomial basis function.

"hyperplane"

The built-in hyperplane basis function.

sFuncName

The name of a user-provided basis function declared in the script. This is case sensitive.

Examples

The following script selects the built-in hyperplane basis function.

L = new_lsqfit()

-- create a CLsqFit object

 

-- no function declared, so n-dimensional polynomial used

L:SetBasisFunc("hyperplane")

-- select built-in function 2, the Hyperplane

sName = L:GetBasisFunc()

 

Printf( "Func= '%s'\n", sName )

-- result: Func= 'hyperplane'

The next example declares a user-defined basis function in the script. This function fits a line. Its name is passed as a string parameter to SetBasisFunc. Remember that your custom basis function name is case-sensitive.

function line( n, c )

-- declare the basis function. n is always passed as 2.

  local b = {}

-- declare a local table for the basis vector

  b[1] = 1

-- basis vector element [1] is 1

  b[2] = c[1]

-- basis vector element [2] is c[1], the "x" coordinate

  return b

-- return the basis vector

end

-- end of the basis function

L = new_lsqfit()

-- create a CLsqFit object

L:SetBasisFunc( "line" )

-- register the script function "Line"

L:SetNumCoefs(2)

-- set the number of coefs for a 1-dimensional fit.

-- add points to the fit

 

L:Fit()

-- fit the data

sName = L:GetBasisFunc()

 

Printf( "Func= '%s'\n", sName )

-- result: Func= 'line'

Related Topics

CLsqFit class

GetBasisFunc

GetBasisDim

SetNumCoefs

Basis Functions

 

 


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