Mathematica 9 is now available
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Mathematica > Data Manipulation > Numerical Data > Curve Fitting & Approximate Functions >
Mathematica > Data Manipulation > Statistics > Curve Fitting & Approximate Functions >
Mathematica > Mathematics and Algorithms > Statistics > Curve Fitting & Approximate Functions >

Fit

Fit[data, funs, vars]
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 {{x_1,y_1,... ,f_1},{x_2,y_2,... ,f_2},...}, where the number of coordinates x,y,... is equal to the number of variables in the list vars.
  • The data can also be of the form {f_1,f_2,...}, 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[{f1, f2, ...}, {1, x, x^2}, x] gives a quadratic fit to a sequence of values fi. The result is of the form a0+a1x+a2x^2, where the ai are real numbers. The successive values of x needed to obtain the fi are assumed to be 1, 2, ... .  »
  • Fit[{{x1, f1}, {x2, f2}, ...}, {1, x, x^2}, x] does a quadratic fit, assuming a sequence of x values xi.  »
  • Fit[{{x1, y1, f1}, ...}, {1, x, y}, {x, y}] finds a fit of the form a0+a1x+a2y.  »
  • 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 fi.  »
  • 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 two 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 a + b x:
Find the minimum symbolically:
These are the coefficients given by Fit:
This is the sum of squares error for a quadratic a + b x + c x2:
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
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team