Recursive Sequence Calculator

Enter the coefficients, seed values, and term count to generate the sequence.

How it is calculated

You supply two starting values and three constants, and the tool builds each new term from the two before it: a(n) = p × a(n−1) + q × a(n−2) + r. The first term listed is a0, the second is a1, the third is p × a1 + q × a0 + r, and so on. Number of terms N says how many terms to list, counting a0 as the first. N must be from 1 to 50; a fractional N is cut to its whole part, and N = 1 shows only a0. Coefficients and seeds may be negative or decimal. The tool returns no result if any term becomes non-finite or larger than about 9 × 1015 in size, because past that point digits would no longer be exact. The list always uses plain dot decimals with no thousands separators, so it can be copied; the last term is shown separately in the page's number format. With p = q = 1, r = 0 and seeds 0 and 1 you get the Fibonacci numbers.

Worked example

Take p = 2, q = 1, r = 0 with a0 = 0 and a1 = 1, the Pell recurrence a(n) = 2·a(n−1) + a(n−2), and ask for 8 terms. The first two are 0 and 1. Then 2×1 + 0 = 2, 2×2 + 1 = 5, 2×5 + 2 = 12, 2×12 + 5 = 29, 2×29 + 12 = 70, 2×70 + 29 = 169. The tool lists 0, 1, 2, 5, 12, 29, 70, 169, and the last term is 169. Each term is slightly more than twice the one before it.

Try this example →

Common mistakes

  • Expecting the count to start from a1 or to leave out a0. The list always starts with a0, so 8 terms ends at the term built from index 7.
  • Treating the constant r as a multiplier. It is added once at every step, not multiplied by an earlier term.
  • Swapping the coefficients. p multiplies the term just before, q the one before that; swapping them gives a different sequence.
  • Asking for more than 50 terms, or for 0 terms. Both give no result.
  • Picking coefficients that grow so fast that a term passes about 9 × 1015, for example p = q = 2 over many terms. The tool then shows nothing rather than inexact digits; ask for fewer terms.

About this calculator

A second-order linear recurrence defines each term from the two before it: a(n) = p·a(n-1) + q·a(n-2) + r. Set p=q=1, r=0 and seed with 0,1 and you get the Fibonacci sequence; different coefficients generate Lucas numbers, Pell numbers, and countless other classic sequences.

Recurrences like this appear throughout computer science and mathematics — analyzing the running time of recursive algorithms, modeling population growth, and describing digital filters in signal processing — because many real processes depend on their two most recent states rather than an explicit formula for the n-th term.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    Changing only the seeds gives a different family with the same rule. With p and q equal to 1 and seeds 2 and 1, the list starts 2, 1, 3, 4, 7, 11, 18, 29, which is the Lucas sequence rather than Fibonacci. This makes the tool handy for checking a hand-written recurrence from a homework problem or a loop you coded: compare the first ten terms before trusting the rest. Which recurrences would you like to see offered as presets?

Popular calculators

All Calculators