GAUSSFIT

The GAUSSFIT function computes a non-linear least-squares fit to a function f  ( x ) with from three to six unknown parameters. f  ( x ) is a linear combination of a Gaussian and a quadratic; the number of terms is controlled by the keyword parameter NTERMS.

This routine is written in the IDL language. Its source code can be found in the file gaussfit.pro in the lib subdirectory of the IDL distribution.

Calling Sequence

Result = GAUSSFIT( X, Y [, A] )

Arguments

X

An n -element vector of independent variables.

Y

A vector of dependent variables, the same length as X .

A

A named variable that will contain the coefficients A of the fit.

Keywords

ESTIMATES

Set this keyword equal to an array of starting estimates for the parameters of the equation. If the NTERMS keyword is specified, the ESTIMATES array should have NTERMS elements. If NTERMS is not specified, the ESTIMATES array should have six elements. If the ESTIMATES array is not specified, estimates are calculated by the GAUSSFIT routine.

NTERMS

Set this keyword to an integer value between three and six to specify the function to be used for the fit. The values correspond to the functions shown below. In all cases:

NTERMS=6 is the default setting. Here, A 0 is the height of the Gaussian, A 1 is the center of the Gaussian, A 2 is the width of the Gaussian, A 3 is the constant term, A 4 is the linear term, and A 5 is the quadratic term.

Example

X = FINDGEN(13)/5 - 1.2 ; Define the independent variables.

Y = [0.0, 0.1, 0.2, 0.5, 0.8, 0.9, $

    0.99, 0.9, 0.8, 0.5, 0.2, 0.1, 0.0] ; Define the dependent variables.

yfit = GAUSSFIT(X, Y, A) ; Fit the data to the default function, storing coefficients in A.

PRINT, A ; Print the coefficients.

IDL prints:

2.25642 -1.62041e-07 0.703372 -1.25634 3.04487e-07 0.513596

We can compare original and fitted data by plotting one on top of the other:

LOADCT, 30 ; Load an appropriate color table.

PLOT, X, Y ; Plot the original data.

OPLOT, X, yfit, COLOR = 100 ; Overplot the fitted data in a different color.

See Also

COMFIT , CURVEFIT , GAUSS2DFIT , POLY_FIT , POLYFITW , REGRESS , SFIT , SVDFIT