FitPoly2d


The FitPoly2d function fits a 2-d polynomial to 3 tables containing x, y, and z values. The fit includes cross terms. CLsqFit object, providing full access to all aspects of the fit.

Syntax

CLsqFit = FitPoly2d( x[], y[], z[], nCoefsX, nCoefsY )

CLsqFit = FitPoly2d( x[], y[], z[], w[], nCoefsX, nCoefsY )

where

    x[] is a lua table containing the x values.

    y[] is a lua table containing the y values.

    z[] is a lua table containing the z (observation) values.

    w[] is an optional lua table containing the weight values.

    nCoefsX, nCoefsY are the number of coefficients in x and y, each between 1 and 10.

    CLsqFit is a CLsqFit object containing the fit properties and results.

 

The multi-dimensional polynomial fit includes cross terms. For example, a fit with nCoefsX=2 and nCoefsY=2 fits a plane but the 3rd coefficient is the cross term a[3]xy. To exclude this or other cross tems, you must use the CLsqFit:ForceCoef method to set each undesired cross term to 0. This can be done 2 ways:

1.   Use the current function for a preliminary fit, then set cross terms, then call CLsqFit:Fit().

2.   Do the fit using the class method, starting with CLsqFit:new().

 

Example

This example fits x,y,z with a warped plane: z = a[1] + a[2]x + a[3]xy + a[4]y:

x = { 12.7, 14, 15, 17.6, 18.24 }

-- x data

y = { 4.1, 2.6, 5,4, 3.5, 7.6 }

-- y data

z = { 24.1, 22.6, 25,4, 23.5, 27.6 }

-- z data (observations)

L = FitPoly2d( x, y, z, 2, 2 )

-- Fits a warped plane

if L:GetStatus() == 0 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