# ExpFitEx

Advanced Analysis Library Only

AnalysisLibErrType ExpFitEx (double arrayX[], double arrayY[], double weight[], int numberOfElements, int fitMethod, double tolerance, double fittedData[], double *amplitude, double *damping, double *residue);

## Purpose

Fits the data set (x, y) to the exponential model using the Least Square, Least Absolute Residual, or Bisquare method. The following equation represents the exponential model:

where a is amplitude and b is damping.
If fitMethod is LEAST_SQUARE, the function finds the amplitude and damping of the exponential model by minimizing the residue as follows:

where | n is numberOfElements
| w i is the i-th element of weight
| f i is the i-th element of fittedData
| y i is the i-th element of arrayY

If fitMethod is LEAST_ABSOLUTE_RESIDUAL, the function finds the amplitude and damping of the exponential model by minimizing the residue as follows:

If fitMethod is BISQUARE, the function finds the amplitude and damping of the exponential model by using reweighted least square fitting iteratively, as shown in the following flowchart:

## Parameters

Input
Name | Type | Description
arrayX | double-precision array | The x value of the data set (x, y).
arrayY | double-precision array | The y value of the data set (x, y). If fittedData is NULL, the best fit array overwrites arrayY.
weight | double-precision array | The weight of each data point. If weight is NULL, the function assumes all the weights are 1.
numberOfElements | integer | The length of arrayX, arrayY, and weight.
fitMethod | integer | The fit method. fitMethod must be one of the following values: LEAST_SQUARE (0) LEAST_ABSOLUTE_RESIDUAL (1) BISQUARE (2) The Least Square method is preferable if the noise of arrayY is Gaussian distributed. The Least Absolute Residual and Bisquare methods are robust fit methods. Therefore, they are preferable if there are outliers in the observations. In most cases, the Bisquare method is less sensitive to outliers than the Least Absolute Residual method.
tolerance | double-precision | The stop criteria. The function adjusts the amplitude and damping iteratively. If the relative difference between residue in two successive iterations is less than tolerance, the function returns the resulting amplitude and damping. If tolerance is less than or equal to 0, the function sets tolerance to 0.0001.
Output
Name | Type | Description
fittedData | double-precision array | The y values calculated using the fitted exponential model. If fittedData is NULL, the best fit array overwrites arrayY.
amplitude | double-precision | The amplitude of the fitted exponential model.
damping | double-precision | The damping of the fitted exponential model.
residue | double-precision | The weighted mean error of the exponential fit. residue is the weighted mean absolute error if fitMethod is LEAST_ABSOLUTE_RESIDUAL, as is shown in the following equation: residue is the weighted mean square error if fitMethod is LEAST_SQUARE or BISQUARE, as is shown in the following equation:

## Return Value

Name | Type | Description
status | AnalysisLibErrType | A value that specifies the type of error that occurred. Refer to analysis.h for definitions of these constants.