Recurrence Relation
solver.
Turn a rule like aₙ = aₙ₋₁ + aₙ₋₂ into a formula for any term, with the steps shown.
- Characteristic equation
- r² − r − 1 = 0
- a₁₄
- 377
- Growth per step
- 1.618
The largest root has size 1.618, so each term is roughly 1.618 times the one before once n is large.
The first terms
Drag the point at n = 1 to change a₁The first 15 terms, a₀ to a₁₄: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, and so on. The largest root has size 1.618, so each term is roughly 1.618 times the one before once n is large.
a₀ to a₁₄
| n | aₙ | Closed form |
|---|---|---|
| 0 | 0 | 0 |
| 1 | 1 | 1 |
| 2 | 1 | 1 |
| 3 | 2 | 2 |
| 4 | 3 | 3 |
| 5 | 5 | 5 |
| 6 | 8 | 8 |
| 7 | 13 | 13 |
| 8 | 21 | 21 |
| 9 | 34 | 34 |
Every input is a whole number, so the terms are worked out exactly, with no rounding.
Working
- 1Try aₙ = rⁿ in the part without crⁿ = rⁿ⁻¹ + rⁿ⁻²r² − r − 1 = 0
- 2Discriminant: p squared plus 4qΔ = 1² + 4 × 1 = 5
- 3Two real rootsr=1 ± √52≈ 1.618 and −0.618
- 4Fit A and B to a₀ and a₁A = 0.4472B = −0.4472
- 5Closed formaₙ = 0.4472(1.618)ⁿ − 0.4472(−0.618)ⁿ
- 6Check: put n = 10 into the closed formClosed form at n = 10: 55Term by term: 55
How it's worked out
A recurrence relation gives each term from the ones before it. This solver handles second-order rules with constant coefficients and an optional constant c. You give it p, q, c and the first two terms, a₀ and a₁.
Step 1: the characteristic equation. Leave c aside and guess a solution of the form rⁿ. Put it into the rule and divide by rⁿ⁻², and a quadratic is left. Its roots decide the shape of the answer.
Step 2: the general solution. With two different roots, every solution is A times r₁ⁿ plus B times r₂ⁿ. With one repeated root r, the second solution is n times rⁿ. The extra n lets the formula match two separate starting values, as Levin's textbook points out.
Complex roots come as a pair with the same size ρ and opposite angles ±θ. Their two powers combine into a real sequence that turns through the angle θ each step while its size changes by the factor ρ.
Step 3: the constant c. Any solution is one particular solution plus a solution of the rule without c. When 1 is not a root, a constant K works. When 1 is a root, the guess gets an extra factor of n, or of n² for a double root, which is the rule in Theorem 6 of the Princeton notes.
Step 4: fit the start. Put n = 0 and n = 1 into the general solution and set them equal to a₀ and a₁. That gives two equations for A and B. The tool then checks the closed form against the terms it works out one by one.
Worked examples
Ways to climb 10 stairs one or two at a time
To reach stair n, your last move came from stair n − 1 or from stair n − 2. So the number of ways is the sum of those two counts. There is one way to stand at the bottom and one way to reach stair 1.
The characteristic equation is r² − r − 1 = 0, with roots (1 + √5)/2 ≈ 1.618 and (1 − √5)/2 ≈ −0.618. Fitting a₀ = a₁ = 1 gives A ≈ 0.7236 and B ≈ 0.2764.
The terms run 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, so there are 89 ways to climb 10 stairs. These are the Fibonacci numbers moved along by one place.
Moves needed for the Tower of Hanoi
To move n disks, you move n − 1 disks out of the way, move the largest disk, then move the n − 1 disks back on top. That is twice the moves for n − 1 disks, plus 1. With no disks there is nothing to move.
Here q = 0, so the roots are 2 and 0, and 1 is not a root. The particular solution is K = 1/(1 − 2) = −1. Fitting a₀ = 0 gives A = 1, so the closed form is 2ⁿ − 1. Ten disks take 1,023 moves.
A repeated root from the Princeton notes
The rule aₙ = 6aₙ₋₁ − 9aₙ₋₂ has the characteristic equation r² − 6r + 9 = 0, which is (r − 3)² = 0. The only root is 3, so the solution takes the form (A + Bn)3ⁿ.
With a₀ = 1 and a₁ = 6, putting n = 0 gives A = 1. Putting n = 1 gives 3(A + B) = 6, so B = 1. The answer is 3ⁿ + n3ⁿ, the same as in the course notes, and the terms run 1, 6, 27, 108, 405, 1458, 5103, 17496.
Reading your result
The largest root sets the growth. Once n is large, the term with the largest root in size swamps the others. The Fibonacci root is about 1.618, so each Fibonacci number is close to 1.618 times the one before, and the 100th is 354,224,848,179,261,915,075.
A root of 1 means steady growth. For sₙ = 2sₙ₋₁ − sₙ₋₂ the root 1 is repeated, so the terms form a straight line. Starting from 3 and 5 they run 3, 5, 7, 9, 11, 13, adding 2 each time.
Small roots mean the sequence settles. For aₙ = 0.5aₙ₋₁ + 3, the root 0.5 shrinks away and the terms close in on K = 6. By n = 11 the term is 5.997.
Complex roots make it cycle. For aₙ = −aₙ₋₂ the roots are ±i, with size 1 and angle a quarter turn. The terms repeat every four steps: 1, 0, −1, 0, 1, 0, −1, 0.
Common mistakes
- Writing the characteristic equation with the wrong signs. From aₙ = p·aₙ₋₁ + q·aₙ₋₂ you get r² − pr − q = 0. Moving the terms across changes their signs, which is the usual slip.
- Using A·rⁿ + B·rⁿ for a repeated root. Two copies of the same root are really one term, so the formula cannot fit two starting values. Use (A + Bn)rⁿ.
- Guessing a constant when 1 is a root. For aₙ = aₙ₋₁ + 3, a constant K would need K = K + 3. Try Kn instead.
- Fitting A and B before adding the particular solution. The starting values belong to the full answer, so add K first and then solve for A and B.