# Curve Fitting

There are many situations where one wants to find a formula that best fits a given set of data. One way to do this in *Mathematica* is to use Fit.

Fit[{f_{1},f_{2},...},{fun_{1},fun_{2},...},x] | find a linear combination of the that best fits the values |

In[1]:= |

Out[1]= |

In[2]:= |

Out[2]= |

In[3]:= |

Out[3]= |

In[4]:= |

Out[4]= |

In[5]:= |

Out[5]= |

In[6]:= |

Out[6]= |

In[7]:= |

Out[7]= |

In[8]:= |

Out[8]= |

{f_{1},f_{2},...} | data points obtained when a single coordinate takes on values |

{{x_{1},f_{1}},{x_{2},f_{2}},...} | data points obtained when a single coordinate takes on values |

{{x_{1},y_{1},...,f_{1}},{x_{2},y_{2},...,f_{2}},...} | data points obtained with values of a sequence of coordinates |

If you give data in the form then Fit will assume that the successive correspond to values of a function at successive integer points . But you can also give Fit data that corresponds to the values of a function at arbitrary points, in one or more dimensions.

Fit[data,{fun_{1},fun_{2},...},{x,y,...}] | fit to a function of several variables |

In[9]:= |

Out[9]= |

In[10]:= |

Out[10]= |

Fit takes a list of functions, and uses a definite and efficient procedure to find what linear combination of these functions gives the best least-squares fit to your data. Sometimes, however, you may want to find a *nonlinear fit* that does not just consist of a linear combination of specified functions. You can do this using FindFit, which takes a function of any form, and then searches for values of parameters that yield the best fit to your data.

FindFit[data,form,{par_{1},par_{2},...},x] | search for values of the that make form best fit data |

FindFit[data,form,pars,{x,y,...}] | fit multivariate data |

Searching for general fits to data.

In[11]:= |

Out[11]= |

In[12]:= |

Out[12]= |

In[13]:= |

Out[13]= |

By default, both Fit and FindFit produce *least-squares* fits, which are defined to minimize the quantity , where the are residuals giving the difference between each original data point and its fitted value. One can, however, also consider fits based on other norms. If you set the option NormFunction->u, then FindFit will attempt to find the fit that minimizes the quantity , where r is the list of residuals. The default is NormFunction->Norm, corresponding to a least-squares fit.

In[14]:= |

Out[14]= |

FindFit works by searching for values of parameters that yield the best fit. Sometimes you may have to tell it where to start in doing this search. You can do this by giving parameters in the form . FindFit also has various options that you can set to control how it does its search.

Searching for general fits to data.

In[15]:= |

Out[15]= |

option name | default value | |

NormFunction | Norm | the norm to use |

AccuracyGoal | Automatic | number of digits of accuracy to try to get |

PrecisionGoal | Automatic | number of digits of precision to try to get |

WorkingPrecision | Automatic | precision to use in internal computations |

MaxIterations | Automatic | maximum number of iterations to use |

StepMonitor | None | expression to evaluate whenever a step is taken |

EvaluationMonitor | None | expression to evaluate whenever form is evaluated |

Method | Automatic | method to use |

Options for FindFit.