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.
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().
This example fits x,y,z with a warped plane: z = a[1] + a[2]x + a[3]xy + a[4]y:
|
-- x data |
|
-- y data |
|
-- z data (observations) |
|
-- Fits a warped plane |
|
-- if fit was not successful, then... |
|
-- get the error channel |
|
-- get the error message |
|
-- exit the script and list the error message |
|
|
|
-- list the standard deviation of the fit |
|
-- do other things with the fit |