# Curve Fitting Functions

The algorithm used to find the best curve fit in the Curve Fitting class is the Least Squares method. This algorithm finds the curve coefficients a, which minimize the squared error e(a) in the following formula:

where f(Xi, a) is the function that represents the desired curve.

You can find the coefficient a by solving the linear system of equations the following formula generates:

Given a set of n sample points (x, y) represented by the sequences X and Y, the curve-fitting functions determine the coefficients that best represent the data. The best fit Z is an array of expected values given the coefficients and the X set of values. Thus, you can express Z as a function of X and the following coefficients:

Z = f(X, a)

When you establish the best fit values, you can obtain the mean squared error (mse) by applying the following formula: