Solving Equations by Iteration

Rearrange to x = g(x), then keep substituting.

An equation with no tidy answer

The equation x² − 4x + 1 = 0 has roots 2 − √3 and 2 + √3, which the quadratic formula gives. Many equations have no such formula: in m = 20 ln(720/m), m appears both outside and inside a logarithm, and no rearrangement leaves it alone on one side. Iteration finds a root as a decimal, to any accuracy wanted, by repeating one simple calculation. The quadratic is a good place to learn it, because its answer can be checked.

Rearrange into x = g(x)

Rearrange the equation until a single x stands alone on one side. Move the 4x across: 4x = x² + 1. Divide by 4: x = (x² + 1)/4.

The right side is called g(x), so the equation now reads x = g(x) with g(x) = (x² + 1)/4. Nothing has been solved yet: there is still an x on the right. But the equation now says something useful. A root is a number that g leaves unchanged.

A root is where y = g(x) meets y = x

Draw y = g(x) and the straight line y = x. Where they cross, the height of the curve equals the height of the line, so g(x) = x. That value of x is a root of x² − 4x + 1 = 0.

A number that g sends to itself is called a fixed point of g. Put 2 − √3 ≈ 0.2679 into g and 0.2679 comes back out.

xyy = xroot

The gold curve is y = (x² + 1)/4 and the dashed line is y = x. They cross at x ≈ 0.2679, where the input to g equals its output.

Feed each answer back in

Start from a rough guess, x₀ = 1, and put it into the right side: x₁ = (1² + 1)/4 = 2/4 = 0.5. Then put x₁ in: x₂ = (0.5² + 1)/4 = 1.25/4 = 0.3125.

Keep going, each output becoming the next input, and keep every digit the calculator gives: x₃ = 0.2744, x₄ = 0.2688, x₅ = 0.2681, x₆ = 0.26796 and x₇ = 0.26795. The values settle toward 2 − √3 = 0.267949…

The rule is written xₙ₊₁ = (xₙ² + 1)/4. Square the old value, add 1, and divide the whole of that by 4.

The staircase

The same steps can be drawn. Start at x₀ = 1 on the x-axis and go vertically to the curve: the height there is g(1) = 0.5, which is x₁. Go horizontally to the line y = x: on that line the height and the x-coordinate are equal, so the point reached is above x₁ = 0.5. Go vertically to the curve again, reaching the height g(0.5) = 0.3125, which is x₂, and horizontally to the line.

Vertically to the curve, horizontally to the line, and repeat. The path is a staircase that closes in on the crossing point.

xyy = x

From x₀ = 1: up to the curve at height 0.5, across to the line, down to the curve at 0.3125, across to the line, and down to 0.2744. Each step is shorter than the one before, and the staircase closes in on the crossing.

How fast it closes in

Compare each value with the root 0.267949. The errors are 0.732, 0.232, 0.0446, 0.0065, 0.00088 and 0.00012. After the first few steps each error is about 0.13 times the one before.

That number is the gradient of the curve at the root. g(x) = (x² + 1)/4 has gradient g'(x) = x/2, and at x = 0.2679 that is 0.134. Near the root the curve is almost a straight line of gradient 0.134, so each step lands about 0.134 times as far from the root as the step before.

When to stop

Stop when successive values agree to the accuracy asked for, and not when one value happens to round correctly. To 4 decimal places, x₆ = 0.26796 and x₇ = 0.26795 both round to 0.2680, but x₈ = 0.267949 rounds to 0.2679. Two values agreeing is a sign, not a proof.

The proof is a change of sign. f(x) = x² − 4x + 1 is continuous, f(0.26785) = 0.00034 is positive and f(0.26795) = −0.0000028 is negative, so a root lies between 0.26785 and 0.26795, and every number there rounds to 0.2679.

The other root runs away

The curve y = (x² + 1)/4 crosses y = x a second time, at 2 + √3 ≈ 3.7321. Start just above it, at x₀ = 3.9, and the values are 4.0525, 4.3557, 4.9930 and 6.4825: each lands further from 3.7321 than the one before. Start just below, at 3.7, and they fall away: 3.6725, 3.6218, 3.5294, heading down to the other root, 0.2679.

The gradient explains it. At 3.7321, g'(x) = x/2 = 1.87, more than 1. Near that root each error is multiplied by about 1.87, so every step makes it bigger.

y = xroot

Near the second root, 3.7321, the gold curve is steeper than the dashed line y = x. From x₀ = 3.9 the staircase climbs away from the crossing, each step longer than the one before.

Another rearrangement

The same equation can be rearranged differently. Divide x² − 4x + 1 = 0 by x: x − 4 + 1/x = 0, so x = 4 − 1/x. Its gradient is 1/x², which is 0.072 at 3.7321, much less than 1.

From x₀ = 4: x₁ = 4 − 1/4 = 3.75, x₂ = 4 − 1/3.75 = 3.7333, x₃ = 3.73214 and x₄ = 3.73206, closing in on 3.7321 quickly. Started from 1, this rearrangement also reaches 3.7321, not 0.2679: near 0.2679 its gradient is 1/0.2679² ≈ 13.9, so that root pushes the values away.

So the test, for any rearrangement x = g(x), is the size of g' near the root. When −1 < g'(x) < 1 there, values that start close enough close in. When g' is bigger than 1 or less than −1, they move away, and another rearrangement is needed.

Closing in from both sides

When g' is negative near the root, the values fall on alternate sides of it. Equal temperatures for a cooling cup and a warming tank lead to m = 20 ln(720/m), whose gradient −20/m is about −0.38 near the root. From m₀ = 50 the values are 53.34, 52.05, 52.54, 52.35, 52.42 and 52.40: above, below, above, below, each nearer than the last.

Drawn, the path is not a staircase but a square spiral, winding in on the crossing.

root

The gold curve is 20 ln(720/m), falling as m rises, and the dashed line marks where the output equals the input. From 50 the path goes up to 53.34, back to 52.05, up to 52.54: a spiral, on alternate sides of the root at 52.4.

The square root of 2, and a rearrangement that never settles

For x² = 2, one rearrangement is x = (x + 2/x)/2. From 1: (1 + 2)/2 = 3/2, then (3/2 + 4/3)/2 = 17/12 ≈ 1.41667, then 1.414216, close to √2 = 1.414214. Check 17/12: 17 × 17 = 289 and 2 × 144 = 288, so (17/12)² = 289/144 is just over 2.

Written as x = 2/x instead, the same equation goes nowhere. From 1 it gives 2, and from 2 it gives 1 again, forever. Here g'(x) = −2/x², which is exactly −1 at √2, so the values neither close in nor move away. When values jump about like this, try another rearrangement.

The usual mistakes

Dividing only the last term. In xₙ₊₁ = (xₙ² + 1)/4 the division line runs under the whole bracket: from 2, the next value is (4 + 1)/4 = 1.25, not 4 + 1/4 = 4.25.

Forgetting to square. The formula squares the previous value first: (2 + 1)/4 = 0.75 leaves out the square.

Giving x₁ when x₂ is asked for. x₂ puts x₁ back through the same formula a second time.

Doubling instead of iterating. The output goes back in as the new input; adding it to itself is not the iteration.

Stopping at the first value that rounds correctly, before two successive values agree.

Two applications

In the first application below, a tank must hold 4 m³ and use 13 m² of steel, which leads to x³ − 13x + 16 = 0 with two positive roots. One rearrangement closes in on the smaller and runs away from the larger, and the gradient test explains why.

In the second, a loan is repaid in three equal payments, and x = 1 + r, one plus the rate of interest, satisfies a cubic. Its rearrangement has a gradient of about 0.35 near the root, so each step is about a third of the one before.

Worked example: An Open Steel Tank with a Square Base: One Rearrangement That Closes In on a Root and One That Runs Away

Question An open tank has a square base of side x m and a height of h m. It must hold 4 m3 and be made from exactly 13 m2 of steel sheet. (a) Show that x3 − 13x + 16 = 0, and use the iteration xn+1 = xn3 + 1613 with x0 = 1.5 to find one possible side to 2 decimal places. (b) The equation has a second positive root near 2.6. Show that the same iteration started at x0 = 2.7 moves away from it, and explain why using g'(x). Then use xn+1 = √13 − 16xn with x0 = 2.6 to find it to 2 decimal places. Give the height of each tank.

  1. 1.The volume gives x2h = 4, so h = 4x2. The steel is the base and four sides: x2 + 4xh = 13. Substitute: x2 + 16x = 13, and multiply by x: x3 − 13x + 16 = 0.

    1.481.491.51.481.491.5side (m), xyy = x2.62.833.22.62.833.2side (m), xyy = xx2h = 4 and x2+ 4xh = 13x2+ 16/x = 13, so x3− 13x + 16 = 0
    1.481.491.51.481.491.5side (m), xyy = x2.62.833.22.62.833.2side (m), xyy = xx2h = 4 and x2+ 4xh = 13x2+ 16/x = 13, so x3− 13x + 16 = 0
    (a) The volume gives h = 4x2, and the steel gives x2 + 4xh = 13. Together, x3 − 13x + 16 = 0.
  2. 2.Iterate xn+1 = xn3 + 1613 from x0 = 1.5: x1 = 3.375 + 1613 = 1.4904, then x2 = 1.4854, x3 = 1.4829 and x4 = 1.4816. The last two both round to 1.48.

    1.481.491.51.481.491.5side (m), xyy = xx0= 1.52.62.833.22.62.833.2side (m), xyy = xxn+1= (xn3+ 16)/13 from 1.51.4904, 1.4854, 1.4829, 1.4816
    1.481.491.51.481.491.5side (m), xyy = xx0= 1.52.62.833.22.62.833.2side (m), xyy = xxn+1= (xn3+ 16)/13 from 1.51.4904, 1.4854, 1.4829, 1.4816
    The staircase for xn+1 = xn3 + 1613 from x0 = 1.5 steps down between the curve and the line y = x.
  3. 3.(a) x = 1.48 m. Check: f(1.475) = 0.034 and f(1.485) = −0.030 have opposite signs. The height of this tank is 41.482 = 1.83 m.

    1.481.491.51.481.491.5side (m), xyy = xx0= 1.51.482.62.833.22.62.833.2side (m), xyy = xx = 1.48 m: f(1.475) > 0 > f(1.485)height 4/1.482= 1.83 m
    1.481.491.51.481.491.5side (m), xyy = xx0= 1.51.482.62.833.22.62.833.2side (m), xyy = xx = 1.48 m: f(1.475) > 0 > f(1.485)height 4/1.482= 1.83 m
    (a) The iterates close in on x = 1.48 m, confirmed by a change of sign. That tank is 1.83 m high.
  4. 4.From x0 = 2.7 the same iteration gives 2.7448, 2.8216, 2.9587 and 3.2230: each step is larger than the one before. Here g'(x) = 3x213, which is about 1.6 near 2.63, more than 1, so each error is multiplied by about 1.6. Near 1.48 it is about 0.51, which is why the first run closed in.

    1.481.491.51.481.491.5side (m), xyy = xx0= 1.51.482.62.833.22.62.833.2side (m), xyy = xx0= 2.7from 2.7: 2.7448, 2.8216, 2.9587, 3.2230g'(x) = 3x2/13 ≈ 1.6 near 2.63: more than 1
    1.481.491.51.481.491.5side (m), xyy = xx0= 1.51.482.62.833.22.62.833.2side (m), xyy = xx0= 2.7from 2.7: 2.7448, 2.8216, 2.9587, 3.2230g'(x) = 3x2/13 ≈ 1.6 near 2.63: more than 1
    From x0 = 2.7 the staircase climbs away from the second root: g'(x) = 3x213 ≈ 1.6 there, more than 1.
  5. 5.Rearrange x2 = 13 − 16x as x = √13 − 16x instead. Its gradient near 2.63 is about 0.44. From x0 = 2.6: x1 = √13 − 6.1538 = 2.6165, then x2 = 2.6239, x3 = 2.6272 and x4 = 2.6287. The last two both round to 2.63.

    1.481.491.51.481.491.5side (m), xyy = xx0= 1.51.482.62.612.622.632.62.612.622.63side (m), xyy = xx0= 2.6xn+1= square root of (13 − 16/xn)its gradient near 2.63 is about 0.442.6165, 2.6239, 2.6272, 2.6287
    1.481.491.51.481.491.5side (m), xyy = xx0= 1.51.482.62.612.622.632.62.612.622.63side (m), xyy = xx0= 2.6xn+1= square root of (13 − 16/xn)its gradient near 2.63 is about 0.442.6165, 2.6239, 2.6272, 2.6287
    The rearrangement x = √13 − 16x has gradient about 0.44 near the second root, and its staircase from x0 = 2.6 closes in.
  6. 6.(b) x = 2.63 m, and the height is 42.632 = 0.58 m. Check: f(2.625) = −0.037 and f(2.635) = 0.040. Both tanks use 13 m2 of steel: one is 1.48 m square and 1.83 m high, the other 2.63 m square and 0.58 m high.

    1.481.491.51.481.491.5side (m), xyy = xx0= 1.51.482.62.612.622.632.62.612.622.63side (m), xyy = xx0= 2.62.63x = 2.63 m: f(2.625) < 0 < f(2.635)height 4/2.632= 0.58 m
    1.481.491.51.481.491.5side (m), xyy = xx0= 1.51.482.62.612.622.632.62.612.622.63side (m), xyy = xx0= 2.62.63x = 2.63 m: f(2.625) < 0 < f(2.635)height 4/2.632= 0.58 m
    (b) x = 2.63 m, a tank 0.58 m high. The same 13 m2 of steel makes a tall tank and a shallow one.

Answer: (a) x3 − 13x + 16 = 0, and x = 1.48 m, a tank 1.83 m high; (b) from 2.7 the iterates grow, because g'(x) = 3x213 ≈ 1.6 > 1 near that root; the second iteration gives x = 2.63 m, a tank 0.58 m high

Common mistakes

  • Deciding from the run away from 2.7 that there is no second root. An iteration that moves away from a root does not show that the root is absent; the change of sign f(2.6) = −0.224 < 0 < f(2.7) = 0.583 shows that it is there.
  • Stopping at x2 = 1.4854 because x1 and x2 both round to 1.49. With a gradient of about 0.5 the iterates are still falling; f(1.485) < 0 shows that the root is below 1.485.

More solving equations numerically problems, worked step by step →

Worked example: A Loan Repaid in Three Equal Yearly Payments: The Rate of Interest from an Iteration

Question A student borrows $10 000 and repays it in three equal payments of $4000, one at the end of each year. Before each payment, interest at a rate r a year is added to what is owed. (a) Write x = 1 + r, and show that 5x3 − 2x2 − 2x − 2 = 0. (b) Use the iteration xn+1 = (2xn2 + 2xn + 25)1/3 with x0 = 1.1 to find x to 4 decimal places, and give the rate of interest as a percentage to 1 decimal place.

  1. 1.After one year the debt is 10 000x, and the first payment leaves 10 000x − 4000. After the second year and payment it is (10 000x − 4000)x − 4000 = 10 000x2 − 4000x − 4000.

    1.0951.0971.0991.0951.0971.099x = 1 + ryy = xy = g(x)after 2 years: 10 000x2− 4000x − 4000x = 1 + r
    1.0951.0971.0991.0951.0971.099x = 1 + ryy = xy = g(x)after 2 years: 10 000x2− 4000x − 4000x = 1 + r
    Each year the debt is multiplied by x = 1 + r and then falls by $4000: after two years it is 10 000x2 − 4000x − 4000.
  2. 2.After the third year and the last payment nothing is owed: 10 000x3 − 4000x2 − 4000x − 4000 = 0. (a) Divide by 2000: 5x3 − 2x2 − 2x − 2 = 0.

    1.0951.0971.0991.0951.0971.099x = 1 + ryy = xy = g(x)10 000x3− 4000x2− 4000x − 4000 = 05x3− 2x2− 2x − 2 = 0
    1.0951.0971.0991.0951.0971.099x = 1 + ryy = xy = g(x)10 000x3− 4000x2− 4000x − 4000 = 05x3− 2x2− 2x − 2 = 0
    (a) After the third payment nothing is owed. Dividing 10 000x3 − 4000x2 − 4000x − 4000 = 0 by 2000 gives 5x3 − 2x2 − 2x − 2 = 0.
  3. 3.Rearrange: 5x3 = 2x2 + 2x + 2, so x = (2x2 + 2x + 25)1/3. Start at x0 = 1.1, a guess of 10%: x1 = (2.42 + 2.2 + 25)1/3 = 1.3241/3 = 1.0981.

    1.0951.0971.0991.0951.0971.099x = 1 + ryy = xy = g(x)x0= 1.1xn+1= ((2xn2+ 2xn+ 2)/5)1/3x1= 1.3241/3= 1.0981
    1.0951.0971.0991.0951.0971.099x = 1 + ryy = xy = g(x)x0= 1.1xn+1= ((2xn2+ 2xn+ 2)/5)1/3x1= 1.3241/3= 1.0981
    The iteration starts at x0 = 1.1: up to the curve y = g(x) for x1 = 1.0981, then across to the line y = x.
  4. 4.Keep the full calculator value each time: x2 = 1.0974, x3 = 1.0971, x4 = 1.0971, x5 = 1.0970 and x6 = 1.0970. Each step is about a third of the one before, because the gradient of g(x) near the root is about 0.35, which is less than 1.

    1.0951.0971.0991.0951.0971.099x = 1 + ryy = xy = g(x)x0= 1.11.0974, 1.0971, 1.0971, 1.0970, 1.0970near the root g'(x) is about 0.35
    1.0951.0971.0991.0951.0971.099x = 1 + ryy = xy = g(x)x0= 1.11.0974, 1.0971, 1.0971, 1.0970, 1.0970near the root g'(x) is about 0.35
    The staircase closes in on the point where y = g(x) meets y = x. Each step is about a third of the one before, because g'(x) ≈ 0.35 there.
  5. 5.(b) x = 1.0970, so r = 0.0970, and the rate of interest is 9.7% a year. Check with x = 1.097: the debt goes 10 970 − 4000 = 6970, then 7646.09 − 4000 = 3646.09, then 3999.76 − 4000 = −0.24, which is zero to the nearest dollar.

    1.0951.0971.0991.0951.0971.099x = 1 + ryy = xy = g(x)x0= 1.11.0970x = 1.0970: a rate of 9.7% a yearcheck: 3646.09 × 1.097 = 3999.76
    1.0951.0971.0991.0951.0971.099x = 1 + ryy = xy = g(x)x0= 1.11.0970x = 1.0970: a rate of 9.7% a yearcheck: 3646.09 × 1.097 = 3999.76
    (b) x = 1.0970, so the rate of interest is 9.7% a year. At that rate the third payment clears the debt to within 24 cents.

Answer: (a) 5x3 − 2x2 − 2x − 2 = 0; (b) x = 1.0970, a rate of 9.7% a year

Common mistakes

  • Spreading the extra $2000 evenly: 200010 000 = 20% over three years, about 6.7% a year. The debt falls after every payment, so interest is charged on less and less, and the true rate is higher.
  • Rearranging as x = 5x3 − 2x2 − 22. Its gradient near the root is 15x2 − 4x2 ≈ 6.8, far more than 1, so the iterates run away from the root instead of closing in.

More solving equations numerically problems, worked step by step →

Practice Solving Equations by Iteration in the app