So far when you've encountered a function, finding the roots analytically (by hand) involved figuring out first what kind of function it was (polynomial, rational, &c. ...), then trying one or more of several methods, including:
But what if there are no rational roots? Then we need some way to numerically estimate what the roots are. After all, it may still be important to find them.
Newton's method works well for a good number of cases, and it's pretty easy to understand. It's all about tangent lines and the derivative.
In the first panel (left) of the figure below we have a function, f(x) (purple curve), with a root we couldn't find using one of the methods above. We first make a guess at the root, say at x1. Then we find the line tangent to f(x) at that point and find where that tangent line intersects the x-axis. Obviously this will involve finding the equation of the tangent line from a point (x1, f(x1)) and the slope, f'(x1). You can see that we've "walked" closer to the actual root.
The point where our first tangent crosses the x-axis is our new "guess," x2. We find the equation of the line tangent to f(x) at x2 and take the x-intercept of that tangent as our new best guess at the root.
Repeating the process gets us even closer to the actual root. In fact, in a case like this, we can get as close as we'd like to the actual root, depending on what kind of precision we require. The error – the difference between our guess and the real value of the root – gets smaller and smaller.
← Here's a blowup of that last step. You can see that where the root of the tangent to the curve at x3 is x4, which is much closer to our elusive actual root (yellow) of f(x). We track our progress by noting that the step size along the x-axis decreases and that f(xn), the value of the function at the nth step, gets smaller.
I'm going to work through one round of Newton's method in this example, then automate the process below with a spreadsheet. Notice that for this quadratic function, we already know the two roots, x = -2, 3. That will make our exploration of the method more meaningful because we know what the answer should be.
First we'll make an initial guess at the root on the left, say x = -4. Now we'll need to calculate f(x) and f'(x):
OK, so remember that we're looking for the equation of the tangent line at x = -4 for the purpose of finding where it crosses the x-axis. That will be our refined "guess" at the root. We have a point and a slope:
So the y-intercept and equation of the line are:
Setting y = 0, we find the x-intercept and our refined root estimate:
Now it remains to keep doing that until the estimates converge
Here's what that first cycle looks like on the graph. The initial guess at the root is x = -4, which generates a second guess of -2.44 on the way to an actual root of x = 2.
Now let's automate this procedure with a spreadsheet. In the table below are the four rounds of Newton's method that converged very nicely to the value of the root. The top row is the initial guess of x = -4.0, and successive rows are refinements of that guess using Newton's method.
Below are similar calculations of the x = -2 and x = 3 roots beginning from different starting guesses, including one that's quite far away, at x = 25.
Notice that in the case of the parabola, we have to make our guess on the correct side of the vertex to get a result. This is important because it means that Newton's method won't always, at least for a given initial guess, converge to a root of the function.
Notice that it takes a few more iterations to get to the root when our starting guess is so far away, but the method still works.
Once in a while, you'll encounter a function in which Newton's method, for one reason or another, doesn't work. One such example is shown here →
The problem in this example, f(x) = ln(x), is that the function is convex on the side of the tangent and the domain is restricted on the left. Thus the first tangent line intersects the x-axis outside the domain of the function and the method is dead. Always be on the lookout for situations like this.
Also notice that if your first guess was between 0 and 1 (x = 1 is the actual root of the log function), the method would work.
Find the nearest root of the function given using the indicated starting point or range.
1. f(x) = x3 + 5x + 2 near x = 0 (one root)
2. f(x) = x4 - 2x3 + 5x2 - 5 in [1, 2] (one root)
3. Use Newton's method to find, correct to six digits, the 6th root of 4, i.e. solve x6 = 4.
4. Find the positive root of sin(x) = x2
xaktly.com by Dr. Jeff Cruzan is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. © 2012, Jeff Cruzan. All text and images on this website not specifically attributed to another source were created by me and I reserve all rights as to their use. Any opinions expressed on this website are entirely mine, and do not necessarily reflect the views of any of my employers. Please feel free to send any questions or comments to email@example.com.