CLsqFit:ForceCoef
The ForceCoef method specifies the value of a specific coefficient. This removes the coefficient from the set being fit and adjusts the fit results accordingly. Use this, for example, if fitting a line and you want the slope to have a specific value such as 1.0.
CLsqFit:ForceCoef( nIndex, nValue )
CLsqFit:ForceCoef( nIndex, nValue, nChan )
where
nIndex is the index of the coefficient in the set of coefficients of the fit. This is a 1-based number.
nValue is the target value of the coefficient.
nChan is an optional parameter that specifies the target channel when fitting multi-channel data.
This method forces 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)and call ForceCoef(2,1.0), then coefficient [2] will be set to the value 1.0 and removed from the set of "free parameters" of the fit. The fit still would use 3 parameters but parameter index 2 would be 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 forcing in one step using ResetForcedCoefs.
The example below illustrates forcing a coefficient in a 2x2 coefficient polynomial fit. After computing the fit, the 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.
|
-- create the least squares fitting object |
|
-- fit a polynomial with 2 coefficients each in 2 dimensions |
|
-- add an (x,y) point |
|
-- add more points... |
|
|
|
|
|
|
|
-- do a 2x2 fit to 4 coefficients |
-- save the results for comparison |
|
|
-- find the 2,2 coefficient in the 2x2 polynomial fit matrix |
|
-- force the cross term at 2,2 to 0. |
|
-- re-do the fit with no cross term. |