---
title: Newton's method
heading: Follow the tangent to the root
eyebrow: A5 · Lesson 34 · Newton's method
xp: 40
---

::: hook
Every circuit simulator, from SPICE to the one in this course, solves its nonlinear equations the same way. Guess the answer, replace each nonlinear part by its tangent line at that guess, solve the now-linear problem, and repeat. Each round roughly doubles the number of correct digits. For a single equation it's Newton's method, and it's the most important numerical idea in this course.
:::

::: play
- The curve is $f(x) = x^2 - 2$; its positive root is $\sqrt2$. The dashed line is the tangent at your guess $x_0$.
- The tangent hits zero at the next guess, $x_1$. Move $x_0$ and watch $x_1$.
- Start at $x_0 = 3$. How close is $x_1$ to $\sqrt2 = 1.41421$? Then imagine starting again from $x_1$.
:::
:::

```sim plot
view: graph
x: x = 0..4
y: y = -3..14
slider: x0 = 0.5..4 step 0.05 = 3
plot: x^2 - 2 | label: f(x) = x² − 2
plot: (x0^2 - 2) + 2*x0*(x - x0) | dashed | color: ch2 | label: tangent at x₀
point: x0, x0^2 - 2 | label: x₀
point: x0 - (x0^2 - 2)/(2*x0), 0 | label: x₁
readout: x₁ = x0 - (x0^2 - 2)/(2*x0) | digits: 8
readout: x₂ = (x0 - (x0^2 - 2)/(2*x0)) - ((x0 - (x0^2 - 2)/(2*x0))^2 - 2)/(2*(x0 - (x0^2 - 2)/(2*x0))) | digits: 8
```

::: predict
## Starting from $x_0 = 1$, one Newton step for $\sqrt{2}$ (on $f = x^2 - 2$) gives what?

- [ ] 1.4
- [x] 1.5
- [ ] 2
- [ ] 1.4142

::: reveal
1.5. $x_1 = x_0 - \frac{f(x_0)}{f'(x_0)} = 1 - \frac{-1}{2} = 1.5$. The next step gives 1.41667, then 1.4142157: the number of correct digits roughly doubles each time.
:::
:::

::: nameit
## The method

At a guess $x_n$, replace $f$ by its tangent line and find where the tangent is zero:

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

Repeat until the change, or $|f(x_n)|$, is small enough.

**For square roots** ($f = x^2 - a$), the step simplifies to $x_{n+1} = \frac{1}{2}\left(x_n + \frac{a}{x_n}\right)$: the averaging rule from A4.

## How fast it converges

Close to a simple root, the error roughly squares each step: $e_{n+1} \approx C e_n^2$. Errors of $10^{-2}$, $10^{-4}$, $10^{-8}$, $10^{-16}$: four steps from two correct digits to full double precision. That's **quadratic convergence**, and it's why simulators converge in a handful of iterations per time step.

Bisection (lesson 6 and A4) gains one bit per step; Newton doubles the digits. But Newton needs a derivative and a decent starting guess.

## How it fails

- **Flat tangent:** if $f'(x_n) \approx 0$, the step shoots off far away.
- **Cycling or wandering:** a bad starting point can bounce between values or head for a different root.
- **Exponentials overshoot.** A diode's $e^{V/V_T}$ is so steep that a guess slightly too high makes a tiny step, and one slightly too low makes a huge one. SPICE limits how far the diode voltage can move per step for exactly this reason ("junction limiting").

Practical solvers combine Newton's speed with a safeguard: bracket the root first, take Newton steps that stay in the bracket, fall back to bisection when they don't.
:::

::: example
## Solve $\cos x = x$ with Newton's method from $x_0 = 1$.

::: solution
1. **Set up.**
   $$f(x) = \cos x - x, \quad f'(x) = -\sin x - 1$$
2. **First step.**
   $$\begin{aligned} x_1 &= 1 - \frac{\cos 1 - 1}{-\sin 1 - 1} \\ &= 1 - \frac{-0.4597}{-1.8415} \\ &= 0.7504 \end{aligned}$$
3. **Keep going.**
   $$x_2 = 0.7391, \quad x_3 = 0.739085$$
4. **Check.** Three steps give six correct digits. The root, 0.7390851, is where the cosine curve crosses the line $y = x$.

**Answer:** $x = 0.739085$ after three steps.
:::
:::

::: example
## A diode ($I_s = 10^{-14}$ A, $V_T$ = 25.85 mV) is in series with 1 kΩ across 5 V. Take one Newton step for the diode voltage from 0.7 V.

::: solution
1. **KCL.** The diode's current must equal the resistor's, so the voltage is a zero of
   $$g(V) = I_s(e^{V/V_T} - 1) - \frac{5 - V}{1000}$$
2. **Derivative.**
   $$g'(V) = \frac{I_s}{V_T}e^{V/V_T} + \frac{1}{1000}$$
3. **Evaluate at 0.7 V.** $I_s e^{0.7/0.02585} = 5.76$ mA and the resistor's current is 4.30 mA, so
   $$g = 1.46\ \text{mA}$$
   $$\begin{aligned} g' &= 0.2228 + 0.001 \\ &= 0.2238\ \text{S} \end{aligned}$$
4. **Newton step.**
   $$\begin{aligned} V_1 &= 0.7 - \frac{0.00146}{0.2238} \\ &= 0.6935\ \text{V} \end{aligned}$$
5. **Check.** The true answer is 0.6925 V; two more steps get it to the microvolt.

**Answer:** one Newton step takes the diode voltage from 0.7 V to 0.6935 V.
:::
:::

::: example
## Find $\sqrt{2}$ with Newton's method on $f(x) = x^2 - 2$, starting from $x_0 = 1$.

::: solution
1. **The Newton step.**
   $$x_{n+1} = x_n - \frac{x_n^2 - 2}{2x_n}$$
2. **Iterate from 1.**
   $$\begin{aligned} x_1 &= 1.5 \\ x_2 &= 1.416\,667 \\ x_3 &= 1.414\,216 \end{aligned}$$
3. **Check.** The true value is 1.414 214. The number of correct digits roughly doubles at each step: 1, 3, 6.

**Answer:** $\sqrt{2} \approx 1.414\,216$ after three steps.
:::
:::

::: check
given: a = 2 | 3 | 5 | 10; x0 = 1 | 2
answer: x0 - (x0^2 - a)/(2*x0)
tolerance: 0.01%

## Take one Newton step toward $\sqrt{\given{a}}$ from $x_0$ = {x0}, using $f(x) = x^2 - \given{a}$.

::: right
Right. $x_1 = x_0 - \frac{x_0^2 - a}{2x_0}$ = {answer}.
:::

::: misses
- [x0 - (x0^2 - a)] Divide by the derivative, $2x_0$.
- [x0 + (x0^2 - a)/(2*x0)] Subtract: $x - f/f'$.
- [sqrt(a)] That's the exact root. One Newton step gets close but not all the way.
- [any] Not yet. $x_1 = x_0 - f(x_0)/f'(x_0)$.
:::
:::

::: check
given: x0 = 0.2 | 0.4 | 0.5 | 0.6 | 0.8 | 1 | 1.2 | 1.5
answer: x0 - (cos(x0) - x0)/(-sin(x0) - 1)
tolerance: 0.01%

## Take one Newton step for $\cos x = x$ from $x_0$ = {x0}.

::: right
Right. With $f = \cos x - x$, $f' = -\sin x - 1$: {answer}.
:::

::: misses
- [x0 - (cos(x0) - x0)/(sin(x0) - 1)] The derivative of $\cos x$ is $-\sin x$.
- [any] Not yet. $f(x) = \cos x - x$, $f'(x) = -\sin x - 1$.
:::
:::

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

## Near a root, Newton's error behaves like $e_{n+1} = \given{C}e_n^2$. Starting with an error of {e}, what is the error after two steps?

::: right
Right. $e_1 = Ce^2$, then $e_2 = Ce_1^2$ = {answer}.
:::

::: misses
- [C*e^2] That's after one step.
- [e/4] Errors don't halve: they square.
- [any] Not yet. Apply $e \to Ce^2$ twice.
:::
:::

::: check
given: Vs = 3 | 5; R = 1000 | 4700; V0 = 0.6 | 0.7
answer: V0 - (1e-14*(exp(V0/0.02585) - 1) - (Vs - V0)/R)/(1e-14/0.02585*exp(V0/0.02585) + 1/R)
tolerance: 0.01%

## A diode ($I_s = 10^{-14}$ A, $V_T$ = 25.85 mV) and {R} Ω are in series across {Vs} V. With $g(V) = I_s(e^{V/V_T} - 1) - (V_s - V)/R$, take one Newton step from $V_0$ = {V0} V.

::: right
Right. $V_1 = V_0 - g(V_0)/g'(V_0)$ = {answer} V.
:::

::: misses
- [any] Not yet. $g'(V) = \frac{I_s}{V_T}e^{V/V_T} + \frac{1}{R}$.
:::
:::

::: check
kind: choice

## Newton's method on $f(x) = x^3 - 2x + 2$ from $x_0 = 0$ gives $x_1 = 1$, then $x_2 = 0$, then 1, 0, ... What went wrong?

- [x] The iteration fell into a cycle; a different starting guess (or a bracket) is needed
- [ ] There's no root
- [ ] The derivative is zero at 0
- [ ] Newton's method only works on quadratics

::: right
Right. Each tangent sends the guess to the other point. The real root, near $-1.77$, is reached from a starting guess like $-2$.
:::

::: misses
- [2] $f$ is a cubic, so it has at least one real root.
- [3] $f'(0) = -2$, not zero.
- [any] Look at the sequence of guesses.
:::
:::

::: check
kind: parts
given: a = 2 | 5 | 10; x0 = 1 | 3

## Find $\sqrt{\given{a}}$ with Newton's method on $x^2 - \given{a}$, from $x_0$ = {x0}.

::: part
answer: x0 - (x0^2 - a)/(2*x0)
tolerance: 0.1%

### What is $x_1$?

::: misses
- [any] $x_1 = x_0 - \frac{x_0^2 - a}{2x_0}$.
:::
:::

::: part
answer: (x0 - (x0^2 - a)/(2*x0)) - ((x0 - (x0^2 - a)/(2*x0))^2 - a)/(2*(x0 - (x0^2 - a)/(2*x0)))
tolerance: 0.01%

### What is $x_2$?

::: misses
- [any] Apply the same step to $x_1$.
:::
:::
:::

::: check
kind: derivation
vars: a = 1..20, x = 0.5..5

## Write Newton's step for the cube root of $a$, using $f(x) = x^3 - a$.

::: step
answer: 3*x^2

### What is $f'(x)$?
:::

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

### Write $x - f(x)/f'(x)$ as one fraction.
:::

::: right
Right. $x_{n+1} = \frac{2x_n^3 + a}{3x_n^2}$: two parts the old guess, one part the correction.
:::
:::

::: explain
## Why do circuit simulators use Newton's method, and why do they limit how far a diode's voltage can move in one step?

::: model
Newton's method replaces each nonlinear part by its tangent at the current guess, which turns the circuit into a linear one that's easy to solve, and near the answer the error squares each round, so a handful of iterations gives full precision. But a diode's current is exponential in its voltage, so a guess that's a little too high gives an enormous current and a wild tangent, and the next step can overshoot badly. Limiting the step in the diode's voltage keeps each iteration in the region where the tangent is a good model, so the fast convergence can take over.
:::
:::

::: practice

::: check
given: a = 7 | 20; x0 = 2 | 4
answer: x0 - (x0^2 - a)/(2*x0)
tolerance: 0.01%

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

::: misses
- [x0 - (x0^2 - a)] Divide by $2x_0$.
- [any] $x - (x^2 - a)/(2x)$.
:::
:::

::: check
given: a = 2 | 3; x0 = 1 | 2
answer: x0 - (x0^3 - a)/(3*x0^2)
tolerance: 0.01%

## One Newton step toward $\sqrt[3]{\given{a}}$ from {x0}, using $f = x^3 - \given{a}$?

::: misses
- [x0 - (x0^3 - a)/(2*x0)] $f' = 3x^2$.
- [any] $x - (x^3 - a)/(3x^2)$.
:::
:::
:::
