fit

From DavinciWiki
Jump to: navigation, search


Description

Least squares curve fitting

Arguments and Return Values

Arguments: Two numeric arrays and fitting options

Return Value: A numeric array containing the fitting coefficients

Usage

Syntax: fit(y=VAL [, x=VAL] [, type=STRING] [, start = INT] [, steps = VAL] [, plot = INT] [, verbose = INT] [, ignore = VAL])

The fit() function performs a non-linear least-squares fit to a data set, using the user specified function type. Currently, only the following six functions are implemented:

  • gauss f(x) = a2exp-(a0-x)/a1)*2
  • gaussc f(x) = a2exp-((a0-x)/a1)*2 + a3
  • gaussl f(x) = a2exp-((a0-x)/a1)*2 + a3 + a4x
  • linear f(x) = a0 + a1x
  • quad f(x) = a0 + a1x + a2x2
  • cube f(x) = a0 + a1x + a2x2 + a3x3

The fit() function uses an iterative method to find the best fit, however by default, only one iteration is performed. The user can specify a larger number of iterations with the 'steps' parameter, or the fit() function can be called repeatedly, using the return values from the previous call as the start parameter for the next call.

If no start parameter is specified, or any of the start parameters are zero, fit() makes a guess based on the function selected and the actual data values. (The marquant-levy fitting method can not handle zero coefficients.)

If the X data values are not specified, channels are used instead, starting at 0.

If type is not specified, it defaults to linear.

The fit() function returns an array of DOUBLEs containing the function coefficients, the chi-squared 'goodness-of-fit' value, and the alamda necessary for the next iteration. The order of these values is defined by the function type selected.

The returned coefficients array is suitable for use as the start values for another iteration of the fit() function.

If the plot keyword is given and is non-null, then the data, and the fitted function are plotted.


Examples

dv> a
100x100x1 array of float, bsq format [40,000 bytes]

dv> b
100x100x1 array of float, bsq format [40,000 bytes]

dv> fit=fit(y=a,x=b,type="linear",plot=1)
2x1x1 array of double, bsq format [16 bytes]
6.08734e-05     0.509038

Images

fit1.png fit2.png fit3.png

DavinciWiki Mini-Nav Bar

Contents


Contact Developers

  • davinci-dev [AT] mars.asu.edu

All other topics

  • See navigation on the left


Recent Core Changes

Modified On: 05-04-2016

Personal tools