---
slug: recurrence-relation-calculator
title: "Recurrence Relation Calculator"
category: math
updated: 2026-11-18
canonical: https://calcseed.com/c/math/recurrence-relation-calculator/
html: /c/math/recurrence-relation-calculator/
---

# Recurrence Relation Calculator

Compute the nth term of a second-order linear recurrence given two initial terms.

## Quick answer

**Quick answer:** with the default inputs (0, 1, 1, 1), the x(n) is **55**. Change any input to update the result.

## Default calculation

Values computed by this calculator at exactly the default inputs listed below.

### Inputs (defaults)

| Input | Value | Unit |
| --- | --- | --- |
| x0 | 0 |  |
| x1 | 1 |  |
| p (coefficient) | 1 |  |
| q (coefficient) | 1 |  |
| n | 10 |  |

### Outputs at these defaults

| Output | Value | Unit |
| --- | --- | --- |
| x(n) | 55 |  |

## Formula

```text
x(n) = p × x(n − 1) + q × x(n − 2)
```

## Inputs

| Variable | Type | Unit | Default |
| --- | --- | --- | --- |
| x0 | number |  | 0 |
| x1 | number |  | 1 |
| p (coefficient) | number |  | 1 |
| q (coefficient) | number |  | 1 |
| n | number |  | 10 |

## Outputs

| Result | Format |
| --- | --- |
| x(n) | primary |
| x(n) | number |

## How it works

### What this calculator does

Enter the two starting terms x0 and x1, the coefficients p and q, and a target index n, and the calculator applies the rule x(n) = p × x(n−1) + q × x(n−2) repeatedly until it reaches x(n). With the defaults x0 = 0, x1 = 1, p = 1, q = 1 and n = 10 it returns x(10) = 55, the tenth Fibonacci number.

### What a recurrence relation is

A recurrence relation defines each term of a sequence using earlier terms, in the way each Fibonacci number is the sum of the two before it. The second-order linear form used here means each term depends on exactly the two previous terms, scaled by fixed coefficients p and q. Once the two starting values and the two coefficients are fixed, the entire infinite sequence is determined.

### Worked example: Fibonacci up to x(10)

Set x0 = 0, x1 = 1, p = 1 and q = 1, so each term is simply the sum of the previous two. The calculator iterates from index 2 upward.

- x(2) = 1 × 1 + 1 × 0 = 1
- x(3) = 1 × 1 + 1 × 1 = 2
- x(4) = 1 × 2 + 1 × 1 = 3
- x(5) = 1 × 3 + 1 × 2 = 5
- Continuing the same addition gives x(6) = 8, x(7) = 13, x(8) = 21, x(9) = 34 and x(10) = 55

The full default sequence is 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55. Ask for n = 9 instead and you get 34, which is why off-by-one indexing is the most frequent source of wrong answers with this tool. The iteration cost is easy to predict: reaching x(n) takes n − 1 applications of the rule, each one two multiplications and an addition, so n = 10 needs 9 steps and n = 1000 needs 999 — instant for the calculator, but worth remembering if you extend the same loop in your own code.

| n | x(n) at the default settings |
| --- | --- |
| 0 | 0 |
| 1 | 1 |
| 2 | 1 |
| 3 | 2 |
| 4 | 3 |
| 5 | 5 |
| 6 | 8 |
| 7 | 13 |
| 8 | 21 |
| 9 | 34 |
| 10 | 55 |

### The characteristic equation

Recurrences of this form also have a closed-form solution built from the characteristic equation r² = p&middot;r + q. For the Fibonacci defaults this becomes r² − r − 1 = 0, whose roots are (1 + &radic;5) ÷ 2 ≈ 1.618034 and (1 − &radic;5) ÷ 2 ≈ −0.618034. The positive root is the golden ratio, and in the long run each Fibonacci term is about 1.618 times the previous one. You can verify the closed form at n = 10: (&phi;^10 − &psi;^10) ÷ &radic;5 ≈ (122.992 − 0.008) ÷ 2.236 ≈ 55.

#### Three root cases

- Two distinct real roots when p² + 4q > 0: the sequence is a blend of two exponential curves
- One repeated root when p² + 4q = 0: terms take the shape (A + B&middot;n)&middot;r^n
- Complex roots when p² + 4q < 0: the sequence oscillates, as with x(n) = x(n−2) − x(n−1)

### Sequences you can model

- Fibonacci: x0 = 0, x1 = 1, p = 1, q = 1, giving x(10) = 55
- Lucas numbers: x0 = 2, x1 = 1, p = 1, q = 1, giving 2, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123
- Pell numbers: x0 = 0, x1 = 1, p = 2, q = 1, giving x(10) = 2376
- Geometric doubling: x0 = 0, x1 = 1, p = 2, q = 0, giving x(10) = 512
- Population models with carryover, where q controls how much the generation two steps back contributes

Changing q to a negative value flips the sequence into oscillation. With p = 0 and q = −1 the defaults produce 0, 1, 0, −1, 0, 1, a repeating cycle of period 4, which is a quick classroom demonstration that recurrences can describe waves as well as growth.

### Common mistakes

- Indexing off by one: x(10) = 55 but x(9) = 34, so confirm whether your course counts x0 as the first term
- Swapping the coefficients: p multiplies x(n−1) and q multiplies x(n−2), and reversing them changes everything
- Ignoring growth: Fibonacci-style terms pass 3.5 × 10^20 by n = 100, so huge n values quickly exceed what a display can show
- Entering a negative n, which the calculator floors to 0 and returns x0
- Assuming fractions fail: coefficients and starting terms may be decimals, for example x1 = 0.5 with p = 1.1

#### A two-term sanity check

A fast sanity check is to recompute the last two steps by hand. For the defaults, x(9) = 34 and x(8) = 21, so x(10) = 34 + 21 = 55. If your result fails that two-term check, the coefficients or the index are set differently than you intended.

## FAQ

### How do I get the Fibonacci sequence?

Set x0 = 0, x1 = 1, p = 1 and q = 1. With n = 10 the calculator returns x(10) = 55, the tenth Fibonacci number counting x0 = 0 as the first.

### What settings produce the Lucas numbers?

Use x0 = 2, x1 = 1, p = 1 and q = 1. The sequence runs 2, 1, 3, 4, 7, 11, 18, 29, 47, 76 and x(10) = 123.

### Can I use negative coefficients?

Yes, any real coefficients are allowed. With p = 0 and q = −1 the defaults cycle 0, 1, 0, −1 and repeat, showing that negative q values produce oscillation instead of growth.

### What does second-order mean?

Each term depends on the two previous terms through p and q. A first-order recurrence would depend only on x(n−1), which is the geometric or arithmetic case.

### How fast does the sequence grow?

For the Fibonacci defaults the growth factor approaches the golden ratio 1.618034 per step. By n = 100 the terms exceed 3.5 × 10^20, which is why large n values produce astronomically large outputs.

### Is there a closed-form formula?

Yes. Solving r² − pr − q = 0 gives roots r1 and r2, and x(n) = A&middot;r1^n + B&middot;r2^n with A and B fixed by x0 and x1. For the defaults this is Binet&rsquo;s formula, which returns exactly 55 at n = 10.

### Why does n = 0 return my x0 value?

The index starts at 0, so n = 0 returns x0 and n = 1 returns x1 without applying the rule at all. The recurrence only kicks in from n = 2 onward.

### Can the terms be decimals?

Yes. Coefficients and initial terms may be any real numbers, for example x0 = 1.5, x1 = 2 with p = 0.5 and q = 0.25, and the iteration handles them the same way.

## Method and sources

Methodology: Results follow exact mathematical definitions; the arithmetic is deterministic and can be verified by hand from the steps shown.

Last updated: 2026-11-18.
- Linear homogeneous recurrence x_n = p x_{n-1} + q x_{n-2}.
