CLsqFit:ForceCoef


The ForceCoef method specifies the value of a specific coefficient. This removes the coefficient from the fit and adjusts the results accordingly. Use this, for example, if fitting a line and you want the slope to have a specific value such as 1.0. To remove a term from the fit, like the xy cross-term in a multidimensional polynomial fit, set its value to 0.0. Note that the forced coefficient is still included in the fit results but uses its assigned value and shows an uncertainty of zero.

Syntax

CLsqFit:ForceCoef( nIndex, nValue )

CLsqFit:ForceCoef( nIndex, nValue, nChannel )

bullet.gif    nIndex is the index of the coefficient in the set of coefficients of the fit. This is a 1-based number.

bullet.gif    nValue is the target value of the coefficient.

bullet.gif    nChannel is an optional parameter that specifies the target channel when fitting multi-channel data.

Remarks

This method forced a coefficient to a specified value. The forced coefficient still is included in the total count of fit coefficients set using the SetNumCoefs method. For example, if you use SetNumCoefs( 3 ) fo a 1-dimensional fit, then call ForceCoef( 2, 1.0 ), the result will be that coefficient [2] is set to the value 1.0 and removed from the set of "free parameters" being fit. The fit still uses 3 parameters but parameter index 2 is discarded from those being fit. The basis function remains unchanged when you force coefficients.

If you are doing a complex fitting procedure and do not remember which coefficients were forced, use the IsCoefForced method to determine if a particular coefficient was forced. To remove dorcing and return a coefficient to being a free parameter of the fit, use UnforceCoef. To fit all coefficients after some were forced, you can remove all forced coeffieicnts in one step using ResetForcedCoefs.

Example

The example below illustrates forcing a coefficient in a 2x2 coefficient polynomial fit. After computing the fit, the xy cross term between x and y is removed by setting it to 0, leaving a fit to an inclined plane rather than a warped plane.

L = new_lsqfit()

-- create the least squares fitting object

 

L:SetNumCoefs( {2,2} )

-- fit a polynomial with 2 coefs each in 2 dimensions

 

L:AddPt( -3, 1, 2 )

-- add an (x,y) point

 

L:AddPt( 4, 5, 3 )

-- add more points...

 

L:AddPt( 10, 8, 6 )

 

 

L:AddPt( 13, 17, 4.5 )

 

 

L:AddPt( 15, 12, 4 )

 

 

L:Fit()

-- do a 2x2 fit to 4 coefficients

 

-- save the results for comparison

 

 

n = GetPolyCoefIndex( {2,2} )

-- find the coef index in the 2x2 polynomial fit matrix

 

L:ForceCoef( n, 0.0 )

-- force the cross term at 2,2 to 0.

 

L:Fit()

-- re-do the fit with no cross term.

 

Related Topics

CLsqFit class, UnforceCoef, IsCoefForced, ResetForcedCoefs, GetPolyCoefIndex


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