How to use the root finder
- Type a function f(x), such as cos(x) - x. The page looks for x where f(x) = 0.
- Enter an interval where the function changes sign. Bisection needs this, and the secant method starts from both ends.
- Optionally set a starting guess for Newton's method, choose which method's iterations to display, and open More options to change the stopping size or the iteration limit.
- Compare the three methods in the table. They should agree on the root, and the iteration counts show how fast each converges.
Formula
bisection: halve [a, b] by keeping the half where f changes sign
Newton: x(next) = x - f(x) / f'(x)
secant: x(next) = x - f(x) (x - x(prev)) / (f(x) - f(x(prev)))
stop when the step is below tolerance x max(1, |x|)
The slope f'(x) in Newton's method is a central difference with a small step, so you can type any function without giving its derivative. Trigonometric functions use radians.
Where cosine meets the line y = x
The default function cos(x) - x on the interval 0 to 1 has its root at 0.7390851332, a number whose digits agree with the known fixed point of cosine. Bisection needs 34 halvings to bring the interval below 1e-10 and ends with f at the root equal to -5.11e-11.
Newton's method started in the middle of the interval takes only 4 iterations and the secant method takes 6. Both land on 0.739085133215 with f equal to 0 to the digits shown. The three roots agree within about 3e-11.
Choosing a method
Bisection is slow but sure. As long as the function is continuous and has opposite signs at the two ends, it must find a root, and each step gains one binary digit. Newton's method is very fast near a simple root but can jump far away if started where the slope is small. The secant method is nearly as fast without needing a slope.
When the methods disagree, they may have found different roots of the same function. Try a narrower interval or a different starting guess. For all the roots of a polynomial at once, the Polynomial Root Finder is better suited.
What a failure message means
If the function has the same sign at both ends, the page says so and does not run bisection. If a step lands where the function is not defined, such as the logarithm of a negative number, that method stops and says why. A zero slope stops Newton's method. Draw the function first with the Graphing Calculator to find a good interval.
More math tools
For other numerical questions, try the Numerical Integration Calculator, Error Propagation Calculator and Minimum Spanning Tree Calculator.
Assumptions and limits
- The function is typed with the variable x and the operators and functions listed on the page, in radians.
- The function is continuous on the interval for bisection to be reliable.
- The tolerance is relative to the size of x, so very large roots need fewer digits of accuracy.
- A converged method has found a point where f is within the tolerance of zero, not exactly zero.
Frequently asked questions
Why do the methods give slightly different roots?
Each stops when its own step is below the tolerance. Bisection stops when the interval is small, while Newton and secant often end closer to the true root because their last step is very accurate.
What if the function crosses zero more than once?
Each method finds one root, usually the one nearest to where it started. Use separate intervals around each crossing to find the others.
Why does bisection need a sign change?
The sign change is how it knows a root lies between the ends. If both ends have the same sign, there may be no root, or an even number of roots, in between.
Can I solve an equation such as x^2 = 5 - x?
Move everything to one side and type x^2 - 5 + x. The root of that function is the solution of the equation.