3.8.1 Curve Fitting

Built into Mathematica are various facilities for finding least-squares fits to data. The basic idea of the fits is to take a list of functions that you specify, and try to find a linear combination of them which approximates your data as well as possible. The goodness of fit is measured by the quantity , where is the value of your data point, and is the value obtained from the fit. The best fit is the one which minimizes .

The basic form of the Fit function.

Some fits to lists of data.

Polynomial fits are the most common kind to use. However, if you have a reason to believe that your data follows some other functional form, you can include the appropriate functions in the list you give to Fit.

There are several common reasons for doing fits.
If you have a particular model for some data, you can do a fit to try and determine the parameters of the model.
Another common use of fits is in finding approximate formulas to describe a particular set of data. You can use the form you get from a Fit as a summary of your actual data.
In the examples of Fit so far, the data points you give are assumed to correspond to the results of evaluating a function of one variable when the variable successively takes on values 1, 2, ... . You can also specify data that depends on several variables, each given an arbitrary sequence of values, not necessarily arranged in any kind of regular array.

Ways of specifying data in Fit.

Fit takes the list of functions you give, and finds the best fit to your data, according to the least-squares criterion, using these functions. There is absolutely no guarantee that the fit you get will in fact accurately reproduce your data. To find out whether it can, you should use statistical testing functions, such as those in the statistics packages available for Mathematica.

Finding exact fits.

If you have sufficiently few data points, then by including sufficiently many terms, you can construct a polynomial which fits your data exactly. In general, if you have data points, you may need a polynomial of degree up to . The function InterpolatingPolynomial gives you such a polynomial. Such polynomials can in fact be useful not only in fitting numerical data, but also in various algebraic algorithms.