CLsqFit:SetBasisFunc


The SetBasisFunc method selects the basis function to use for the fit. This function selects the two built-in basis functions or a named custom basis function you specify in the script. Before writing a custom basis function, read the Basis Functions topic.

Syntax

CLsqFit:SetBasisFunc( BasisFuncChoice )

bullet.gif    BasisFuncChoice is a number 1 or 2 for a built-in basis function.

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

Remarks

This function takes either a number of string value to select the basis function. Mira interprets a number value as a built-in basis function. A string is interpreted as the name of a function in the script:

1

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

2

The built-in hyperplane basis function.

strName

The name of a user-provided basis function declared in the script.

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( 2 )

-- select built-in function 2, the Hyperplane

sName = L:GetBasisFunc()

 

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

-- result: Func= '2'

 

The next example declares a user-defined basis function in the script. This function fits a line:

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], or 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 more 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, Copyright Ⓒ 2023 Mirametrics, Inc. All Rights Reserved.