Practice: Newton and the secant method
Newton steps by hand and a cycle where the tangent does not help, the usual mistakes, transfer questions and a Python implementation: practice for the lecture on methods that use the slope.
Last updated:
On this practice page we practise:
- Newton and secant steps by hand, following the number of correct digits;
- recognizing a cycle, divergence and a double root, and what a program should check;
- avoiding the usual mistakes of Newton and the secant method;
- proving that the order of convergence of the secant method is the golden ratio, and bounding Newton’s error before the first step;
- implementing Newton and the secant method in Python and comparing their cost.
This practice follows the lecture Using the Slope: the Secant Method and Newton–Raphson:
read it or attend it first.
By hand: Newton steps, and a cycle
- For and do three Newton steps. After each step, write the error . What happens to the number of correct digits from step to step?
- For start at and compute , and . What happens, and why does the tangent idea not help here?
- Start the same function at . What changes? What would you add to a program to notice the problem of question 2?
Hint for question 1
The Newton step for simplifies to .
Solutions
- (error ), (error ), (error ). The number of correct digits is , and : the ratio between consecutive steps is and then , so it nearly doubles at each step, because . This is quadratic convergence.
- and , so . Then and , so , and . The iteration jumps between and forever: the tangent at each point points to the other point, and the method never approaches the root.
- From we get and the iteration converges to the root . A program should use the guards of the course conventions: a cap on the number of steps, a check that decreases, and a fall-back to bisection on a bracket.
A real application: implied volatility
An option’s price depends on a number , the volatility, which measures how much the underlying price is expected to jiggle.
A known formula turns into a price . The market gives us the price, and we want the behind it.
A trading system has to compute it for thousands of options every time prices move, so every step saved in one computation is saved thousands of times.
Take a call option on the S&P 500 index (SPX) with strike 7650 that expires on 15 April 2027, 181 days ahead, so years.
On Friday 16 October 2026 it was quoted at 422.8 (bid) and 428.4 (ask); we use the middle, 425.6.
Solve , that is, find a root of
where is the strike price, is the price for delivery on the expiry date as the market sets it, is the discount factor (what one unit of currency arriving on the expiry date is worth today), and is the cumulative distribution function of the standard normal distribution, a library function.
For the numerical task, is a function we can evaluate, with a slope we can write down.
The finance in 20 seconds
An option is the right to buy at the strike price on the expiry date.
The higher the expected jiggle , the more the right is worth, so grows with .
The that reproduces today’s market price is the implied volatility:
the market’s own estimate of future movement. and are read from the market itself, from the prices of calls and puts at the same strikes, so no interest rate or dividend has to be assumed.
Quotes are from Interactive Brokers (delayed, frozen), from 16 October 2026.
The slope of with respect to , called vega, has a closed formula, , where is the normal density.
So Newton–Raphson fits here. Open the explorer with Newton selected and the implied-volatility example (the start is ) and step.
It also offers the yield of the bond from the bisection practice and the example “Newton from far”, which starts at .
The explorer needs JavaScript. The table below shows the steps of Newton on the same problem.
From the true value is (16.295%), and the errors of Newton are:
| Step | Estimate | at the estimate | Error |
|---|---|---|---|
| 0 | 0.3 | 286.7 | |
| 1 | 0.16317718607595 | 0.465 | |
| 2 | 0.16295375646352 | ||
| 3 | 0.16295375229691 |
Steps to reach by the explorer’s rule, on the bracket (the secant method starts from the two ends, Newton from ):
bisection 43, regula falsi 5, secant 5, Newton–Raphson 3. The answer: the implied volatility of the option is about 16.295%, and three Newton steps are enough to reach it.
Work it out: in the example “Newton from far”, with , the first step jumps to million.
Explain why (hint: what is vega when the volatility is almost zero?).
Solution
At the price barely depends on , so vega is almost zero (about ).
The tangent is almost horizontal, and the Newton step divides an ordinary number by a tiny one, so it jumps very far.
Common mistakes
“Newton always converges, and always faster.”
Why this is wrong
It converges fast only near the root and when the slope is not close to zero.
From (the starting volatility of the implied volatility problem) it explodes, and on from 0 it cycles for ever.
Bisection is slower but never fails inside a bracket.
“Stop when two consecutive estimates are close.”
Why this is incomplete
Close estimates can mean convergence, but also a very flat function or a slowly crawling method.
As in the course conventions, check both the step size and against the tolerance.
“Quadratic convergence means fewer evaluations of everything.”
Why this is wrong
It means fewer steps. Each Newton step also needs the derivative; when the derivative is expensive, the secant method with its cheaper steps can finish first.
Transfer practice
- Do two Newton steps by hand for starting at , and compare with
- Newton’s method on some equation gave the errors in four successive steps. About how many correct digits are there after each step, and what does that say about the order of convergence?
- In the implied volatility problem we look for the volatility at which the model price of the option equals the market price, that is a root of . Why does Newton fail when it starts from ?
- Which method would you choose when (a) is the output of a long simulation, (b) is known and you have a good start, (c) an automated pipeline must always return an answer?
Hint for question 1
For the slope is , so .
Solutions
- and , which differs from by . One more step gives , error : close to the root the error is roughly squared each time.
- The number of correct digits is : 1.5, 3.0, 6.1 and 12.2 (rounded). Each number is about twice the one before, so each error is roughly the square of the previous one, which is what order 2 means.
- At the price barely depends on , so vega, the slope , is almost zero. The tangent is almost horizontal and crosses zero very far away.
- (a) The secant method (no derivative), preferably started inside a bracket; (b) Newton–Raphson; (c) a bracketing method, or a combination of a bracket with a fast method, because only a bracket gives a guarantee.
Proof: the Order of the Secant Method
Suppose is twice continuously differentiable on an interval around a root , that is a simple root () with , and that the sequence of the secant method is defined for every (), converges to , and has no term equal to .
Write . Prove that the order of convergence is , that is,
for a constant .
Hint: the error relation
For the two latest points the errors satisfy
where is the slope of the secant line and is a point between the smallest and the largest of , and (the block “An alternative proof with divided differences”, after the solution, shows where the relation comes from).
Try to deduce the order from it: (1) what is the limit of the ratio ?
(2) what does a logarithm turn the product into? (3) which well-known recurrence appears, and what are the roots of ?
Solution
-
The coefficient has a limit. lies between the smallest and the largest of , and , and , so by the squeeze theorem .
By the mean value theorem for some between and ; in the same way , and since is continuous, .
Since is continuous too,Moreover for every , because .
-
A logarithm turns the product into a sum. Let and .
Taking absolute values in and multiplying by gives , and taking :By step 1, . Since , . Up to a constant, is times the number of correct digits, because .
-
The Fibonacci recurrence. Without this is the recurrence of the Fibonacci sequence, .
A sequence with satisfies it exactly when , that is, .
The roots are and , with and . So we expect :
the number of correct digits is multiplied by about in each step.
The next step proves this, with . -
The deviation tends to 0. Let . By step 2 and ,
Since , , so , and therefore .
Take and such that for every . We prove by induction on that .
Base case, : . Induction step: assume the bound for ; thenSince , , so for every large enough .
This holds for every , so . -
Back to the errors. , so . Substituting gives , and therefore
This is order with . In addition, and , so .
Note: matching powers alone (assume , substitute, and get ) assumes that the limit exists.
Step 4 proves that it does.
An alternative proof with divided differences
This proof derives the error relation of the hint, and then reaches the order with approximations.
We use the divided difference, and , and the identity from the proof on the convergence-rate page:
for the line through and , . Here and , so is the secant line, its slope is , and is its zero.
Write for the root and .
- Put and : .
- is a line with slope and , so .
- Equate (1) and (2) and divide by (nonzero when the line is not horizontal): with .
- for some between the smallest and the largest of the three points. Indeed, the function is zero at and at (where agrees with ) and at (by step 1). By Rolle’s theorem (the mean value theorem when the values at the two ends are equal), has a zero between each two neighbouring points of the three, and has a zero between those two zeros. is a line and the product is a parabola with leading coefficient 1, so , and gives the claim. With it, step 3 is exactly the relation of the hint.
- Since , , assuming and . That is, .
- Let , so . Taking logarithms, satisfies , like the Fibonacci sequence.
- Every solution of is , with and : such a combination satisfies the recurrence, and can be chosen to match and , and these two terms determine all the others. Since , the term fades away, so grows like , and .
- means , that is, : order of convergence .
Steps 6 to 8 treat the approximate recurrence as if it were exact; this is the usual textbook argument.
Step 4 of the solution above shows that the conclusion holds with the error term .
Check the relation on an example. For with the secant method from and :
compute and compare it with .
Solution
, , so . The ratio is . For the slope of the secant line is and , so the relation is exact with coefficient .
The same run continues with , and so on: for every is a fraction, computed exactly.
The errors and two ratios:
| 0 | 0.204 | ||
| 1 | 0.2857 | 0.764 | |
| 2 | 0.3415 | 0.403 | |
| 3 | 0.3517 | 0.616 | |
| 4 | 0.3535 | 0.477 |
Which numbers do the last two columns approach, according to the solution of the proof?
Why does the last column jump above and below its limit, with jumps that shrink?
Hint
The limit of the last column is with . For the jumps, look at step 4 of the solution:
by step 5, the last column divided by its limit is .
Solution
, and the third column, , approaches it. The last column approaches .
The last column divided by is , and with .
Near the root is tiny, so each is about times the one before:
its sign flips and its size shrinks by a factor of about in each step.
Indeed , and the following ones are , , , and , and the ratios between neighbours are , , and .
More exercises
Newton and the secant method on
The equation ( in radians) has one root, Let .
- Do three Newton steps from . Write a table with , , and the number of correct digits .
- Run the secant method from and up to , with the same columns.
- Suppose an evaluation of costs as much as one of . How many evaluations does each method use until it has at least 9 correct digits, and how many correct digits does it have then? Which number does the ratio between the numbers of correct digits of consecutive steps approach in each method?
Hint
. Set the calculator to radians, keep the full value in its memory (with Ans) and round only when you write.
The secant step is . Newton’s step needs and at ; the secant step that gives needs only the new value , because is known from the step before.
Solution
- Newton:
| 0 | 1 | 0.58 | |
| 1 | 0.750363867840 | 1.95 | |
| 2 | 0.739112890911 | 4.56 | |
| 3 | 0.739085133385 | 9.77 |
For example . The ratio of the error to the square of the previous error is , and , and it approaches .
- The secant method:
| 0 | 0 | 1 | 0.13 |
| 1 | 1 | 0.58 | |
| 2 | 0.685073357326 | 1.27 | |
| 3 | 0.736298997614 | 2.56 | |
| 4 | 0.739119361912 | 4.47 | |
| 5 | 0.739085112127 | 7.68 | |
| 6 | 0.739085133215 | 12.80 |
- Newton reaches 9.77 digits at , after and at , and : 6 evaluations. The secant method first passes 9 digits at , after at : also 6 evaluations, but with 12.80 digits. After 4 evaluations the two are level: Newton’s has 4.56 digits and the secant method’s has 4.47. The ratios of digits are , and for Newton, approaching 2, and , , and for the secant method (from on), approaching . Per evaluation the secant method gains more here, as the factors against predict.
Two roots:
The function has two roots, and .
- Run Newton from , , and . For each start write and , and say which root the iteration reaches.
- Without computing, which root does Newton reach from any start , and which from any start ? Justify with the identity from how wrong is one step and with the condition that holds from any start on the right side.
- From the first step jumps to . Why, and how does the iteration come back?
Hint
is zero at , negative to its left and positive to its right, and .
At , . In part 2, apply the identity with the root on the same side of as , and look at the sign of .
Solution
- The steps:
| 0 | 0.5 | 0.610060 | |
| 1 | 0 | 0.5 | |
| 1.2 | 2.074315 | 1.724221 | |
| 2 | 1.683518 | 1.543482 |
From : and , so . From : , so exactly, and from there the run is the run from , one step later.
From 0 and from 2 the error is below after 5 steps.
-
Take and the root , which is also left of .
The identity gives with and , so .
If we are done. Otherwise, on the interval we have , and , and , so by the condition for any start on the right side Newton from converges to .
In the same way, for and the root : , so , and on we have , and , so the iteration converges to .
At the tangent is horizontal and the step is undefined.
The table agrees: 0 and 1 are left of , and 1.2 and 2 are right of it. -
, almost zero, and , so the step is and .
Far to the right dominates: the step is , so each step moves left by about 1:
, , and so on. Since the iteration reaches , as part 2 says, but only after 78 steps does the error drop below , against 5 steps from 2.
A double root:
The polynomial has a double root at () and a simple root at .
- Show that Newton’s step is , and that the error satisfies . What is when the iteration converges to 1?
- From compute , and and the ratios . How many steps does one more correct digit cost near the root?
- From the distances from the root are , , , and . What is different, and why?
- When , about how large is ? Computing near 1 in binary64 has a rounding error of a few times . What does this mean for the stopping test on ?
Hint
, so cancels in . For the error put .
In part 4, .
Solution
- for . With : . So , and when the limit is : linear convergence with ratio .
- , and . The ratios are , and , and they approach . Halving the error adds digits, so a digit costs about steps, as in bisection: from it takes 27 steps to reach .
- At the root is simple, , and the convergence is quadratic: the numbers of correct digits are , , , and , almost doubling. At the derivative is zero at the root, so on every interval around it there is no , as in the example in a double root.
- , below the rounding error of the computation. So in binary64 the computed is rounding noise while the error is still about : Newton from in binary64 computes exactly after about thirty steps (the exact count depends on how is written), with an error of a few times , and stays there. The test on is passed with only about 8 correct digits. Near a double root a small residual does not mean a small error: the bound from when to stop needs .
Newton on a cube root
The function (the real cube root, negative for negative ) is increasing, and its only root is .
- Show that for Newton’s step is . Compute from , and the values .
- Which condition of the local convergence statement fails, although the slope is far from zero?
- A program computes and in every step. What do they show here in the first steps, and what should the program do?
Hint
for , so .
Solution
- , so . From : , , , , and is , , , , , multiplied by in each step. The error doubles and changes sign in every step, from every start , however close to the root.
- Near the slope is large, so a bound exists, but does not exist (the tangent at the root is vertical) and is unbounded near . No interval around the root has , so does not exist. The tangent at is so steep that it crosses the axis at , on the other side and twice as far.
- is , , , , and grows: neither becomes small, and both grow in every step. The guards of the course conventions protect the program: the cap on the number of steps ends the loop, and a check that decreases notices the growth already in the first step; then the program should fall back to bisection on a bracket, for example , where .
Which method gains more per evaluation
Near the root a method of order multiplies the number of correct digits by in each step, and when a step costs evaluations of , the factor per evaluation is .
Suppose an evaluation of costs a fraction of an evaluation of , so a Newton step costs .
- For , and compute Newton’s factor and compare it with the secant method’s factor .
- For which do the two methods gain digits equally fast per evaluation?
- For , about how many evaluations does each method need to go from 1 correct digit to 12, if the factors hold from the start?
Hint
After evaluations, 1 correct digit becomes about digits, where is the factor per evaluation.
In part 2 take logarithms of .
Solution
- : , the secant method gains more. : , the secant method still gains a little more. : , Newton gains more.
- means , so . Newton gains more per evaluation when costs less than about 44% of an evaluation of , for example when reuses most of the work already done for .
- gives : for Newton , for the secant method . So about 7 against 5 evaluations. The factors describe the methods near the root; far from it they say nothing.
A bound before the first step:
The root of is . Follow the procedure for bounding Newton’s error with .
- Find , , and , and check that .
- Is in ? Compute the bound for , and compare it with the actual errors of Newton from , which are , and .
- Compute also the one-step bound with the actual error of the previous step, for . Why is it much closer to the actual error?
Hint
and both increase on , and is never zero, so the extreme values are at the ends of .
Solution
- . , , and .
- , so , with and . The bound gives , and for : above the actual errors in every step, but at about 200 times larger. The bound squares again and again, while the actual errors shrink faster.
- against , and against : within a factor of 2. The actual coefficient approaches , and is about times larger.
Root finding, cell by cell
The secant method and Newton–Raphson on new equations that a calculator solves only with SOLVE (the calculator’s command for solving an equation).
Check the conditions first (the value of and of at the start, and whether the first step stays near the root), then fill the iteration table one cell at a time and read the order of convergence from it.
Up to three calculators can sit beside the table.
The workout needs JavaScript. Without it, practise with the example above: Newton on x² − 2 from x₀ = 1 gives x₁ = 1.5, x₂ = 1.41667, x₃ = 1.41422.
Implement it yourself
Complete the two functions below: Newton’s step and the secant step.
The program runs both on and compares with . Press Run; if a line says FAIL, find out why before opening the solution.
Afterwards, compare how many steps each method took, and why the secant method needed one more.
Python in this task. It asks you to write code: two lines inside functions that are already written.def defines a function; for n in range(1, max_steps + 1) repeats with max_steps; abs(step) is ; return x, n gives back two values; math.sqrt(2) is ; repr(x) writes the number x with all the digits needed to tell it from its neighbours.
import math
def f(x):
return x * x - 2
def df(x):
return 2 * x
def newton(f, df, x, tol=1e-12, max_steps=50):
for n in range(1, max_steps + 1):
# TODO: Newton's step, f(x) divided by f'(x)
step = 0.0
x = x - step
if abs(step) <= tol:
return x, n
return x, max_steps
def secant(f, x0, x1, tol=1e-12, max_steps=50):
for n in range(1, max_steps + 1):
# TODO: the secant step, using only the values of f at
# x0 and x1
x2 = x1
if abs(x2 - x1) <= tol:
return x2, n
x0, x1 = x1, x2
return x1, max_steps
for name, (x, n) in [
("Newton from 1", newton(f, df, 1)),
("secant from 1, 2", secant(f, 1, 2))
]:
print(
"ok " if abs(x - math.sqrt(2)) < 1e-10 else "FAIL",
name, "x =", repr(x), "after", n, "steps"
)
ok Newton from 1 x = 1.414213562373095 after 6 steps
ok secant from 1, 2 x = 1.4142135623730951 after 7 steps
Solution
In newton replace the TODO line by
step = f(x) / df(x)
and in secant by
x2 = x1 - f(x1) * (x1 - x0) / (f(x1) - f(x0))
Newton took 6 steps and the secant method 7: the secant method uses an estimate of the slope instead of the true slope, so its order is and not 2.
As a further step, count how many times each function is evaluated in total, as the lesson’s cost discussion suggests, and try starting Newton at to see what happens when the slope is zero.
One more run: a tolerance below the gap. Beside the gap between stored binary64 numbers is (see a tolerance cannot be smaller than the gap), so a tolerance of is below it.
In the code, Newton’s method tests abs(step) and the secant method tests abs(x2 - x1).
Work out which of the two can produce a value below here.
Then add these two lines at the end of the completed program, run it, and read the number of steps in each result:
print(newton(f, df, 1, 1e-16))
print(secant(f, 1, 2, 1e-16))
(1.414213562373095, 50)
(1.414213562373095, 9)
Solution
Only the secant method can. Two stored numbers beside differ by 0 or by at least one gap, so is below only when it is 0.
Newton’s step is with , and at the two stored numbers beside we have , never 0, so the step is never below .
Newton’s method runs all 50 steps and returns (1.414213562373095, 50).
At the step is , about 0.7 of a gap. The exact result of subtracting it lies nearer to the stored number one gap below than to , so it is rounded there.
From that number has the opposite sign and the step has the same size upward, which rounds back.
The iterate jumps between two neighbours, every step is larger than the tolerance, and only the cap on the steps stops the loop.
With the secant formula of the lesson, the secant method returns after 9 steps, (1.414213562373095, 9):
its last step lands on the same stored number, so . A tolerance below the gap can be met only by equal numbers, and the tolerance cannot make a method produce them.
This is why the course conventions ask for a cap on the number of steps.
Continue learning
Back to the lecture Using the Slope: the Secant Method and Newton–Raphson.
The glossary has the terms: glossary.