This is documentation for Mathematica 5, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

Documentation / Mathematica / The Mathematica Book / Advanced Mathematics in Mathematica / Numerical Operations on Functions /

3.9.6 Numerical Root Finding

NSolve gives you a general way to find numerical approximations to the solutions of polynomial equations. Finding numerical solutions to more general equations, however, can be much more difficult, as discussed in Section 3.4.2. FindRoot gives you a way to search for a numerical solution to an arbitrary equation, or set of equations.

Numerical root finding.

The curves for and intersect at one point.

In[1]:= Plot[{Cos[x], x}, {x, -1, 1}]

Out[1]=

This finds a numerical approximation to the value of at which the intersection occurs. The 0 tells FindRoot what value of to try first.

In[2]:= FindRoot[Cos[x] == x, {x, 0}]

Out[2]=

In trying to find a solution to your equation, FindRoot starts at the point you specify, and then progressively tries to get closer and closer to a solution. Even if your equations have several solutions, FindRoot always returns the first solution it finds. Which solution this is will depend on what starting point you chose. If you start sufficiently close to a particular solution, FindRoot will usually return that solution.

The equation has an infinite number of solutions of the form . If you start sufficiently close to a particular solution, FindRoot will give you that solution.

In[3]:= FindRoot[Sin[x] == 0, {x, 3}]

Out[3]=

If you start with , you get a numerical approximation to the solution .

In[4]:= FindRoot[Sin[x] == 0, {x, 6}]

Out[4]=

If you want FindRoot to search for complex solutions, then you have to give a complex starting value.

In[5]:= FindRoot[Sin[x] == 2, {x, I}]

Out[5]=

This finds a zero of the Riemann zeta function.

In[6]:= FindRoot[Zeta[1/2 + I t] == 0, {t, 12}]

Out[6]=

This finds a solution to a set of simultaneous equations.

In[7]:= FindRoot[{Sin[x] == Cos[y], x + y == 1},
{{x, 1}, {y, 1}}]

Out[7]=

The variables used by FindRoot can have values that are lists. This allows you to find roots of functions that take vectors as arguments.

This is a way to solve a linear equation for the variable x.

In[8]:= FindRoot[{{1, 2}, {3, 4}} . x == {5, 6}, {x, {1, 1}}]

Out[8]=

This finds a normalized eigenvector x and eigenvalue a.

In[9]:= FindRoot[{{{1, 2}, {3, 4}} . x == a x, x.x == 1},
{{x, {1, 1}}, {a, 1}}]

Out[9]=