---
title: Newton's method and the secant method
heading: Follow the tangent, and double your digits every step
eyebrow: A13 · Lesson 6 · Newton's method and the secant method
xp: 40
---

::: hook
Every circuit simulator, every power-flow program and every square-root instruction in a processor runs on the same idea, Newton's: replace the curve by its tangent line, and jump to where the tangent crosses zero. Near a simple root it converges **quadratically**: the number of correct digits roughly doubles with each step, so five or six steps take a decent guess to full double precision. Far from the root it can do anything, which is why real implementations guard it. The **secant method** gets nearly the same speed without needing the derivative.
:::

::: play
- The dashed lines are tangents: from $(x_0, f(x_0))$ the tangent meets zero at $x_1$, and the tangent at $x_1$ meets zero at $x_2$. The root of $x^3 - 2x - 5$ is 2.0945514815....
- Start at 3.5: the readouts show the correct digits growing roughly 1, 2, 5, 10, as each error is about the square of the one before.
- Now start near 0.82, where the curve is flat: the tangent is nearly horizontal and throws $x_1$ far away. Newton's method needs a good start.
:::
:::

```sim plot
view: graph
x: x = -1..4
y: y = -15..30
slider: x0 = -1..4 step 0.01 = 3.5
plot: x^3 - 2*x - 5 | label: f(x) = x³ − 2x − 5
plot: ((x0)^3 - 2*(x0) - 5) + (3*(x0)^2 - 2)*(x - x0) | dashed | label: tangent at x₀
plot: (((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)))^3 - 2*((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2))) - 5) + (3*((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)))^2 - 2)*(x - (x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2))) | dashed | color: ch3 | label: tangent at x₁
point: x0, ((x0)^3 - 2*(x0) - 5) | label: x₀
point: (x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)), 0 | label: x₁
point: ((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)) - (((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)))^3 - 2*((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2))) - 5)/(3*((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)))^2 - 2)), 0 | label: x₂
readout: x₁ = (x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2))
readout: x₂ = ((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)) - (((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)))^3 - 2*((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2))) - 5)/(3*((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)))^2 - 2))
readout: x₃ = (((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)) - (((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)))^3 - 2*((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2))) - 5)/(3*((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)))^2 - 2)) - ((((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)) - (((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)))^3 - 2*((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2))) - 5)/(3*((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)))^2 - 2)))^3 - 2*(((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)) - (((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)))^3 - 2*((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2))) - 5)/(3*((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)))^2 - 2))) - 5)/(3*(((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)) - (((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)))^3 - 2*((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2))) - 5)/(3*((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)))^2 - 2)))^2 - 2))
readout: error of x₃, digits = -log(abs((((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)) - (((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)))^3 - 2*((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2))) - 5)/(3*((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)))^2 - 2)) - ((((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)) - (((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)))^3 - 2*((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2))) - 5)/(3*((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)))^2 - 2)))^3 - 2*(((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)) - (((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)))^3 - 2*((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2))) - 5)/(3*((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)))^2 - 2))) - 5)/(3*(((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)) - (((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)))^3 - 2*((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2))) - 5)/(3*((x0 - ((x0)^3 - 2*(x0) - 5)/(3*(x0)^2 - 2)))^2 - 2)))^2 - 2)) - 2.0945514815423265) + 1e-17)
```

::: predict
## Newton's method for $\sqrt2$ is $x \leftarrow \frac12(x + 2/x)$. Starting from 1, how many steps reach 12 correct digits?

- [ ] 2
- [x] 4
- [ ] 12
- [ ] 40

::: reveal
Four: 1.5, 1.41667, 1.4142157, 1.414213562375. The errors are $8.6 \times 10^{-2}$, $2.5 \times 10^{-3}$, $2.1 \times 10^{-6}$, $1.6 \times 10^{-12}$: each roughly the square of the last (divided by $2\sqrt2$).
:::
:::

::: nameit
## Newton's method

$$x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)}$$

the zero of the tangent line at $x_n$. Expanding f about the root shows that near a simple root ($f'(x^*) \ne 0$)

$$e_{n+1} \approx \frac{f''(x^*)}{2f'(x^*)}\,e_n^2$$

**quadratic convergence**: once the error is small, it squares each step. It's fixed-point iteration with $g = x - f/f'$, which has $g'(x^*) = 0$.

## How it fails

- **A flat spot:** where $f' \approx 0$, the step is huge.
- **A bad start:** for $x^3 - 2x + 2$, starting at 0 gives 1, 0, 1, 0, ... forever.
- **A multiple root** of order m: convergence drops to linear, with rate $\frac{m - 1}{m}$.
- **Exponentials** (diodes, transistors): from too low a voltage, one step can land where $e^{V/nV_T}$ overflows. Circuit simulators limit each junction's step to a few $nV_T$.

## Useful Newton iterations

| Solve | Iteration |
|---|---|
| $x^2 = a$ | $x \leftarrow \frac12(x + a/x)$ |
| $1/x = a$ (division without dividing) | $x \leftarrow x(2 - ax)$ |
| $x^3 = a$ | $x \leftarrow x - \frac{x^3 - a}{3x^2}$ |

## The secant method

Replace $f'(x_n)$ with the slope through the last two points:

$$x_{n+1} = x_n - f(x_n)\frac{x_n - x_{n-1}}{f(x_n) - f(x_{n-1})}$$

It converges with order $\varphi = \frac{1 + \sqrt5}{2} \approx 1.618$ using one new function value per step, against Newton's two (f and f′), so per evaluation it's often faster.
:::

::: example
## Solve the diode circuit of lesson 4, $f(V) = \frac{5 - V}{1000} - 10^{-14}(e^{V/0.02585} - 1) = 0$, by Newton's method from 0.8 V and from 0.5 V.

::: solution
1. **From 0.8 V.** The iterates are 0.7745, 0.7498, 0.7267, 0.7077, 0.6962, 0.6927, 0.692492, 0.6924904.
2. **Why it starts slowly.** At first it moves about 25 mV per step: the exponential's tangent is steep, so each step undershoots. Then it converges quadratically.
3. **From 0.5 V.** The first step goes to 4.6 V, where
   $$e^{V/nV_T} \approx 10^{77}$$
   an overflow away from disaster.
4. **What simulators do.** That's why simulators limit voltage steps.

**Answer:** from 0.8 V Newton reaches 0.6924904 V in eight steps; from 0.5 V its first step jumps to 4.6 V, which is why simulators limit voltage steps.
:::
:::

::: example
## Find $1/7$ without dividing, from $x_0 = 0.1$.

::: solution
1. **The iteration.**
   $$x \leftarrow x(2 - 7x)$$
2. **Iterate from 0.1.** It gives 0.13, 0.1417, 0.1428478, 0.1428571422.
3. **The error squares.** The error $1 - 7x$ goes 0.3, 0.09, 0.0081, 0.000066, 0.0000000043.

**Answer:** four steps reach 0.1428571422, with the error squaring at each step.
:::
:::

::: example
## Find the first root of $\tan x = x$ above π by Newton's method, starting at 4.5.

::: solution
1. **Why not use tan directly.** $x - \tan x$ has poles that can throw Newton far away.
2. **Multiply through by $\cos x$.** The new function has the same roots and no poles:
   $$\begin{aligned} f(x) &= \sin x - x\cos x \\ f'(x) &= x\sin x \end{aligned}$$
3. **Iterate from 4.5.** The iterates are 4.493419010, then 4.493409458, after which nothing changes: two steps gave nine digits.
4. **The general point.** Rewriting an equation so its function is smooth near the root is often worth more than any refinement of the method.

**Answer:** the root is 4.493409458, found to nine digits in two steps.
:::
:::

::: check
given: a = 2 | 3 | 10; x0 = 1 | 2 | 3
answer: (x0 + a/x0)/2
tolerance: 0.1%

## One Newton step for $\sqrt{\given{a}}$ from $x_0$ = {x0}: what's $x_1$?

::: right
Right. $\frac12\left(x_0 + \frac{a}{x_0}\right)$ = {answer}.
:::

::: misses
- [x0 - (x0^2 - a)] The step divides by $f'(x_0) = 2x_0$.
- [any] Not yet. $x_1 = x_0 - \frac{x_0^2 - a}{2x_0}$.
:::
:::

::: check
given: c = 2 | 5 | 20; x0 = 1 | 2 | 3
answer: x0 - (x0^3 - c)/(3*x0^2)
tolerance: 0.1%

## One Newton step for $x^3 = \given{c}$ from $x_0$ = {x0}: what's $x_1$?

::: right
Right. {answer}.
:::

::: misses
- [x0 - (x0^3 - c)/(2*x0)] The derivative of $x^3$ is $3x^2$.
- [any] Not yet. $x_1 = x_0 - \frac{x_0^3 - c}{3x_0^2}$.
:::
:::

::: check
given: C = 0.5 | 2 | 0.35; e = 0.01 | 0.001
answer: C*e^2
tolerance: 0.5%

## Near a simple root, Newton's error obeys $e_{n+1} \approx Ce_n^2$ with C = {C}. If $e_n$ = {e}, what's $e_{n+1}$?

::: right
Right. $Ce_n^2$ = {answer}.
:::

::: misses
- [C*e] That's linear convergence; Newton squares the error.
- [any] Not yet. $e_{n+1} = Ce_n^2$.
:::
:::

::: check
given: m = 3 | 4 | 5
answer: (m - 1)/m
tolerance: 0.5%

## Newton's method approaches a root of multiplicity {m}. By what factor does each step shrink the error?

::: right
Right. $\frac{m - 1}{m}$ = {answer}: linear, and slow.
:::

::: misses
- [1/m] The error keeps a fraction $(m - 1)/m$, not $1/m$.
- [any] Not yet. For $f = (x - x^*)^m$, the step removes $\frac1m$ of the error.
:::
:::

::: check
given: a = 3 | 7 | 9; x0 = 0.1 | 0.2
answer: x0*(2 - a*x0)
tolerance: 0.1%

## One step of $x \leftarrow x(2 - ax)$ toward $1/\given{a}$ from $x_0$ = {x0}: what's $x_1$?

::: right
Right. {answer}.
:::

::: misses
- [any] Not yet. $x_1 = x_0(2 - ax_0)$.
:::
:::

::: check
given: c = 2 | 3 | 5
answer: 2 - (4 - c)*(2 - 1)/((4 - c) - (1 - c))
tolerance: 0.1%

## For $f(x) = x^2 - \given{c}$, one secant step from $x_0 = 1$ and $x_1 = 2$: what's $x_2$?

::: right
Right. {answer}.
:::

::: misses
- [2 - (4 - c)/4] That's a Newton step from 2; the secant uses the slope through both points, 3.
- [any] Not yet. $x_2 = x_1 - f(x_1)\frac{x_1 - x_0}{f(x_1) - f(x_0)}$.
:::
:::

::: check
kind: choice

## Newton's method needs f and f′ each step; the secant method needs one new f. If f′ costs as much as f, which reaches a given accuracy with fewer evaluations, near a simple root?

- [ ] Newton, because order 2 beats 1.618
- [x] The secant method: per evaluation, its order is 1.618, against Newton's $\sqrt2 \approx 1.414$
- [ ] They're always equal
- [ ] Neither converges

::: misses
- [1] Newton's step costs two evaluations, so per evaluation its order is $2^{1/2}$.
- [3] The order per evaluation differs.
- [4] Both converge from a good start.
:::
:::

::: check
kind: parts
given: c = 2 | 3 | 5

## Find the cube root of {c} as the root of $f(x) = x^3 - \given{c}$.

::: part
answer: 2 - (8 - c)/7
tolerance: 0.5%

### What does one secant step from $x_0 = 1$ and $x_1 = 2$ give?

::: misses
- [2 - (8 - c)/12] That's Newton's step from 2.
- [any] $x_2 = x_1 - f(x_1)\frac{x_1 - x_0}{f(x_1) - f(x_0)}$.
:::
:::

::: part
answer: 2 - (8 - c)/12
tolerance: 0.5%

### What does one Newton step from 2 give?

::: misses
- [any] $x_1 = 2 - \frac{8 - c}{3 \cdot 4}$.
:::
:::
:::

::: check
kind: derivation
vars: a = 0.5..10, x = 0.5..3

## Write Newton's step for two classic functions.

::: step
answer: x*(3 - a*x^2)/2

### For $f(x) = 1/x^2 - a$, whose root is $1/\sqrt a$?
:::

::: step
answer: (2*x + a/x^2)/3

### For $f(x) = x^3 - a$?
:::

::: right
Right. The first needs no division at all, which is why it's used for fast inverse square roots in graphics hardware.
:::
:::

::: explain
## Why do the correct digits roughly double with each Newton step near a simple root?

::: model
Newton's method replaces f by its tangent line at the current guess and solves that line exactly. The only thing the tangent gets wrong is the curvature of f, and by Taylor's theorem that mistake is proportional to the square of the distance from the root: $f(x^*) = f(x_n) + f'(x_n)(x^* - x_n) + \frac12f''(\xi)(x^* - x_n)^2$. So the new error is a constant times the old error squared. If the error is $10^{-3}$, the next is about $10^{-6}$ and then $10^{-12}$: the number of correct digits doubles each step, as long as $f'(x^*)$ isn't zero.
:::
:::

::: practice

::: check
given: a = 5 | 50; x0 = 2 | 7
answer: (x0 + a/x0)/2
tolerance: 0.1%

## Newton step for $\sqrt{\given{a}}$ from {x0}?

::: misses
- [any] $\frac12(x_0 + a/x_0)$.
:::
:::

::: check
given: m = 2..9 int
answer: (m - 1)/m
tolerance: 0.5%

## Newton's rate at a root of multiplicity {m}?

::: misses
- [any] $(m - 1)/m$.
:::
:::

::: check
given: C = 1.5 | 0.2; e = 0.02 | 0.0001
answer: C*e^2
tolerance: 0.5%

## $e_{n+1}$ for C = {C}, $e_n$ = {e}?

::: misses
- [any] $Ce_n^2$.
:::
:::
:::
