This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

Fit

Fit
finds a least-squares fit to a list of data as a linear combination of the functions funs of variables vars.
  • The data can have the form , where the number of coordinates , , ... is equal to the number of variables in the list vars.
  • The data can also be of the form , with a single coordinate assumed to take values 1, 2, ....
  • The argument funs can be any list of functions that depend only on the objects vars.
  • Fit gives a quadratic fit to a sequence of values . The result is of the form , where the are real numbers. The successive values of needed to obtain the are assumed to be 1, 2, ... . »
  • Fit does a quadratic fit, assuming a sequence of values . »
  • Fit always finds the linear combination of the functions in the list funs that minimizes the sum of the squares of deviations from the values . »
  • Exact numbers given as input to Fit are converted to approximate numbers with machine precision. »
Here is some data:
Find the line that best fits the data:
Find the quadratic that best fits the data:
Show the data with the two curves:
Here is some data:
In[1]:=
Click for copyable input
Find the line that best fits the data:
In[2]:=
Click for copyable input
Out[2]=
Find the quadratic that best fits the data:
In[3]:=
Click for copyable input
Out[3]=
Show the data with the two curves:
In[4]:=
Click for copyable input
Out[4]=
Here is some data defined with exact values:
Fit the data to a linear combination of sine functions using machine arithmetic:
Fit the data using 24-digit precision arithmetic:
Show the data with the curve:
Here is some data in three dimensions:
Find the plane that best fits the data:
Show the plane with the data points:
Find the quadratic that best fits the data:
The quadratic actually interpolates the data:
Here is a list of values:
Fit to a quadratic. When coordinates are not given, the values are assumed to be paired up with 1, 2, ...:
Fit to a quartic:
Show the data with the curve:
Fit gives the best fit function:
LinearModelFit allows for extraction of additional information about the fitting:
Extract the fitted function:
Extract additional results and diagnostics:
Here is some data:
This is the sum of squares error for a line :
Find the minimum symbolically:
These are the coefficients given by Fit:
This is the sum of squares error for a quadratic :
Find the minimum symbolically:
These are the coefficients given by Fit:
When a polynomial fit is done to a high enough degree, Fit returns the interpolating polynomial:
The result is consistent with that given by InterpolatingPolynomial:
Here is some data from a random perturbation of a Gaussian:
This is a function that gives the standard basis for polynomials:
Show the fits computed for successively higher-degree polynomials:
The problem is that the coefficients get very small for higher powers:
Giving the basis in terms of scaled and shifted values helps with this problem:
New in 1