Mathematica 9 is now available
 Documentation / Mathematica / Built-in Functions / Numerical Computation / Data Manipulation  /
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 , , ... , , , , ... , , ... , 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 , , ... , 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[ , , ... , 1, x, x^2 , x] gives a quadratic fit to a sequence of values . The result is of the form + x + x^2, where the are real numbers. The successive values of x needed to obtain the are assumed to be 1, 2, ... .
  • Fit[ , , , , ... , 1, x, x^2 , x] does a quadratic fit, assuming a sequence of x values .
  • Fit[ , , , ... , 1, x, y , x, y ] finds a fit of the form + x + y.
  • Fit always finds the linear combination of the functions in the list forms 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.
  • See the Mathematica book: Section 1.6.6Section 3.8.1.
  • See also Implementation NotesA.9.44.25MainBookLinkOldButtonDataA.9.44.25.
  • See also: Interpolation, InterpolatingPolynomial, Solve, PseudoInverse, QRDecomposition, FindMinimum.
  • Related packages: Statistics`NonlinearFit`, Statistics`LinearRegression`.

    Further Examples

    You will have to evaluate all the cells in this example to regenerate the data used for the plots.
    Here is a table of the first 20 primes.

    In[1]:=

    Here is a plot of this data.

    Evaluate the cell to see the graphic.

    In[2]:=

    This gives a quadratic fit to the data.

    In[3]:=

    Here is a plot of the quadratic fit.

    Evaluate the cell to see the graphic.

    In[4]:=

    This shows the quadratic fit superimposed on the original data. The quadratic fit is better than the linear one.

    Evaluate the cell to see the graphic.

    In[5]:=

    This gives a table of the values of an exponential function for x from 1 to 10 in steps of 1.

    In[6]:=

    Out[6]=

    This fit recovers the original functional form.

    In[7]:=

    Out[7]=

    If you include other functions in the list, Fit determines that they occur with small coefficients.

    In[8]:=

    Out[8]=

    You can use Chop to get rid of the terms with small coefficients.

    In[9]:=

    Out[9]=

    In[10]:=



    Any questions about topics on this page? Click here to get an individual response.Buy NowMore Information
    THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
    SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.