finds numerical values of the parameters pars that make expr give a best fit to data as a function of vars.


finds a best fit subject to the parameter constraints cons.

Details and Options

  • The data can have the form {{x1,y1,,f1},{x2,y2,,f2},}, 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 {f1,f2,}, with a single coordinate assumed to take values 1, 2, .
  • FindFit returns a list of replacements for par1, par2, .
  • The expression expr must yield a numerical value when pars and vars are all numerical.
  • The expression expr can depend either linearly or nonlinearly on the pari.
  • In the linear case, FindFit finds a globally optimal fit.
  • In the nonlinear case, it finds in general only a locally optimal fit.
  • FindFit[data,expr,{{par1,p1},{par2,p2},},vars] starts the search for a fit with {par1->p1,par2->p2,}.
  • FindFit by default finds a leastsquares fit.
  • The option NormFunction->f specifies that the norm f[residual] should be minimized.
  • The constraints cons can contain equations, inequalities, or logical combinations of these.
  • The following options can be given:
  • AccuracyGoalAutomaticthe accuracy sought
    EvaluationMonitorNoneexpression to evaluate whenever expr is evaluated
    FitRegularizationNoneregularization for pars for models
    GradientAutomaticthe list of gradient components for expr
    MaxIterationsAutomaticmaximum number of iterations to use
    MethodAutomaticmethod to use
    NormFunctionNormthe norm to minimize
    PrecisionGoalAutomaticthe precision sought
    StepMonitorNoneexpression to evaluate whenever a step is taken
    WorkingPrecisionAutomaticthe precision used in internal computations
  • The default settings for AccuracyGoal and PrecisionGoal are WorkingPrecision/2.
  • The settings for AccuracyGoal and PrecisionGoal specify the number of digits to seek in both the values of the parameters returned, and the value of the NormFunction.
  • With NormFunction->f and FitRegularization->rfun, Fit finds the values of pars that minimize normf[{expr(pars,x1,y1,)-f1,}]+rfun[pars].
  • The setting for NormFunction can be given in the following forms:
  • fa function f that is applied to the residual
    {"HuberPenalty",α}sum of the Huber penalty function for each component
    {"DeadzoneLinearPenalty",α}sum of deadzone linear penalty function for each component
  • The setting for FitRegularization may be given in the following forms:
  • Noneno regularization
    rfunregularize with rfun[a]
    {"Tikhonov", λ}regularize with
    {"LASSO",λ}regularize with
    {"Variation",λ}regularize with
    {"TotalVariation",λ}regularize with
    {"Curvature",λ}regularize with
    {r1,r2,}regularize with the sum of terms from r1,
  • FindFit continues until either of the goals specified by AccuracyGoal or PrecisionGoal is achieved.
  • Possible settings for Method include "ConjugateGradient", "PrincipalAxis", "LevenbergMarquardt", "Newton", "NMinimize", and "QuasiNewton", with the default being Automatic.


open all close all

Basic Examples  (1)

Find a nonlinear fit to a list of primes:

Click for copyable input

Fit the best-fit parameters , , and :

Click for copyable input

Evaluate the fitted function:

Click for copyable input

Scope  (7)

Options  (7)

Applications  (7)

Properties & Relations  (6)

Possible Issues  (1)

Introduced in 2003
Updated in 2019