FitLine


The FitLine function fits a line to 2 tables containing x values and y values. This method creates a CLsqFit object, providing full access to all aspects of the fit.

Syntax

CLsqFit = FitLine( x[], y[] )

CLsqFit = FitLine( x[], y[], w[] )

where

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

    y[] is a lua table containing the y values (observations).

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

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

Example

This example fits x and y tables of numbers:

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

-- x data

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

-- y data

L = FitLine( x, y )

-- Fit the line, return a CLsqFit object

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

FitPoly

CLsqFit class