This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)
 Documentation / Mathematica / Built-in Functions / Numerical Computation / Equation Solving  /
FindRoot

  • FindRoot[ lhs == rhs , x , ] searches for a numerical solution to the equation lhs == rhs, starting with x = .
  • FindRoot[ lhs == rhs , x , , ] searches for a solution using and as the first two values of x. This form must be used if symbolic derivatives of the equation cannot be found.
  • FindRoot[ lhs == rhs , x , xstart , xmin , xmax ] searches for a solution, stopping the search if x ever gets outside the range xmin to xmax.
  • FindRoot[ , , ... , x , , y , , ... ] searches for a numerical solution to the simultaneous equations .
  • FindRoot returns a list of replacements for x, y, ... , in the same form as obtained from Solve.
  • FindRoot has attribute HoldAll.
  • If you specify only one starting value of x, FindRoot searches for a solution using Newton's method. If you specify two starting values, FindRoot uses a variant of the secant method.
  • If all equations and starting values are real, then FindRoot will search only for real roots. If any are complex, it will also search for complex roots.
  • You can always tell FindRoot to search for complex roots by adding 0. I to the starting value.
  • The following options can be given:
  • The default setting for AccuracyGoal is 10 digits less than WorkingPrecision.
  • If FindRoot does not succeed in finding a solution to the accuracy you specify within MaxIterations steps, it returns the most recent approximation to a solution that it found. You can then apply FindRoot again, with this approximation as a starting point.
  • The size of each step taken in Newton's method is multiplied by the setting given for DampingFactor.
  • See the Mathematica book: Section 1.5.7, Section 1.6.3Section 3.9.6.
  • See also Implementation NotesA.9.44.23MainBookLinkOldButtonDataA.9.44.23.
  • See also: NSolve, Solve, FindMinimum.
  • Related package: NumericalMath`InterpolateRoot`.

    Further Examples

    These two curves intersect at one point.

    Evaluate the cell to see the graphic.

    In[1]:=

    This finds a numerical approximation to the x coordinate of the intersection point. The is the initial guess.

    In[2]:=

    Out[2]=

    Trignometric equations typically have an infinite number of roots. If you start sufficiently close to a particular root of an equation, FindRoot will find that root.

    In[3]:=

    Out[3]=

    Starting closer to another root will give different solution.

    In[4]:=

    Out[4]=

    You can restrict FindRoot to a region in which to look for solutions. Here the initial guess is and the solution is supposed to be between and . There is no such solution.

    In[5]:=

    FindRoot::regex: Reached the point {0.221296} which is outside the region {{0.5, 1.5}}.

    Out[5]=

    This is what happens when FindRoot can find no solutions at all.

    In[6]:=

    FindRoot::cvnwt: Newton's method failed to converge to the prescribed accuracy after 15 iterations.

    Out[6]=

    If you want FindRoot to use complex values in its search, then you need to give a complex starting value.

    In[7]:=

    Out[7]=

    For this equation, FindRoot has difficulty using Newton's method with only the default setting.

    In[8]:=

    Abs[x]
    FindRoot::frjc: Could not symbolically find the Jacobian of {E - 2}. Try giving two starting values for each variable.

    Abs[x]
    FindRoot::frjc: Could not symbolically find the Jacobian of {E - 2}. Try giving two starting values for each variable.

    FindRoot::frjc:
    Could not symbolically find the Jacobian of
    Abs[x]
    {E - 2}. Try giving two starting values
    for each variable.

    FindRoot::frjc:
    Could not symbolically find the Jacobian of
    Abs[x]
    {E - 2}. Try giving two starting values
    for each variable.

    General::stop:
    Further output of FindRoot::frjc
    will be suppressed during this calculation.

    Out[8]=

    When you specify the Jacobian (derivative), Newton's method can be used.

    In[9]:=

    Out[9]=

    When you don't know the Jacobian or it cannot be expressed by a formula, you can use the secant method by giving two starting values.

    In[10]:=

    Out[10]=

    Here is a way to count the number of times FindRoot evaluates the function.

    In[11]:=

    In[12]:=

    In[13]:=

    Out[13]=

    In[14]:=

    The advantage of Newton's method is that it usually converges faster and takes fewer steps than the secant method.

    In[15]:=

    In[16]:=

    In[17]:=

    Out[17]=

    In[18]:=

    This finds a solution to a set of simultaneous equations. It is a good idea to avoid taking the starting values for x and y to be equal or to take any other "special" combinations of values.

    In[19]:=

    Out[19]=

    If you specify the Jacobian in a problem with several variables, you need to make sure the rows and columns are ordered properly.

    In[20]:=

    Out[20]=

    The criterion FindRoot uses for convergence to a root is how close the function is to zero. If the function is very flat it may be close to zero before the variable is close enough to the root.

    In[21]:=

    Out[21]=

    Here FindRoot stopped when the value of the function was within the default AccuracyGoal (6 digits) of zero, but the root is only good to one decimal place.

    In[22]:=

    Out[22]=

    To get closer to the actual value of the root, increase the setting of the AccuracyGoal option. It is often also necessary to increase the setting of the WorkingPrecision option.
    In this case, FindRoot does not make it to the specified AccuracyGoal. The convergence to this root is very slow; we get decimal places.

    In[23]:=

    FindRoot::cvnwt: Newton's method failed to converge to the prescribed accuracy after 15 iterations.

    Out[23]=

    If you think that FindRoot is getting close to a root but may need more steps to get there, increase the setting of the MaxIterations option.

    In[24]:=

    Out[24]=