CLsqFit:Eval CLsqFit:GetBasisFunc

CLsqFit:Fit


The Fit method computes the least squares fit using the current data sample and class properties. As per standard practice, the fit is calculated about the mean value in each dimension. This minimizes the projected uncertainty when predicting values using the fit coefficients. The table below shows the relationship between your variables x,y,z,..., the observed value v, the mean values, and the predicted value of the function using the estimated coefficients.

The coordinate data and observed value V are entered directly using CLsqFit:AddPt or other method. Mira then calculates the mean values internally as part of the fitting process. These means are automatically included when evaluating the fit using CLsqfit:Eval and other methods in the CLsqFit class.

Syntax

bSuccess = CLsqFit:Fit()

bullet.gif    bSuccess is a success code, with true indicating success and false indicating failure. If the fit fails, false is returned. Error information can be obtained using GetErrChan and GetErrMsg.

Remarks

After calling Fit, the function value should be predicted using the Eval method. If your script estimates the function value without using Eval, be sure to subtract the mean value of each coordinate as shown above,nect to Predicted value of fit.

Example

This example creates a CLsqFit object, adds some points, and then computes the fit. if the fit is not successful, the script lists error information and exits.

L = new_lsqfit()

-- create a CLsqFit object

L:SetNumCoefs( 2 )

-- set 2 coefficients to fit a line

L:AddPt( 3.5, 5.15 )

-- add a point for x = 3.5, y = 5.15

L:AddPt( -12, 14 )

-- add a point

L:AddPt( -2, -4.25 )

-- add a point

bSuccess = L:Fit()

-- Fit the line, check the results

if not bSuccess then

-- if fit was not successful, then...

  n = L:GetErrChan()

-- get the error channel

  s = L:GetErrMsg(n)

-- get the error message

  Exit( Sprintf("Error [%d] %s\n", n, s ) )

-- exit the script and list the error message

end

 

Printf( "Sdev=%lg", L:GetSigmaFit() )

-- list the standard deviation of the fit

 

-- do other things with the fit

Related Topics

CLsqFit class

fitpoly1d

GetErrMsg

GetErrChan

DoRejection

 


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