Method of Common Differences
Also known as the Method of Finite Differences

Let's say you have a quadratic sequence. For example,
1, 2, 21, 58, 113, 186…
and you'd like to figure out an expression that will generate the rest of the numbers. One such expression happens to be
9n^{2} +10n + 2,
but you don't know that. How can you find it? By using this method.



Save some time
If you just want the formulas, they are at the bottom of the page. 




How to use this method
You pick any three adjacent numbers from the sequence above — let's take 21, 58, and 113 — and substitute them into a couple of formulas we're about to figure out.
The formulas give you back three new numbers a, b, and c. Those are the coefficients of a quadratic expression that generates the sequence.
In this example, the formulas would give you 9, 10, and 2 . You'd plug them into a quadratic expression like this:
9n^{2} + 10n + 2,
and that's your answer.* 



Deriving the method
You don't need to watch me derive the formulas if you're only interested in using them. If that's the case, just skip down to the bottom of the page and copy the formulas from the summary.
But if you'd like to see how these formulas get figured out, read this section. You only need highschool algebra to follow along.
We'll create three simultaneous equations that show how our three numbers i, j, and k get generated by the unknown expression we're searching for. The first number, i, is generated when we plug n = 1 into that expression. The next number, j, since it's the very next number in the sequence after i, is generated by n = 2. And similarly, k is generated by n = 3. We start with the quadratic formula. 
We use this formula to create three simultaneous equations: 
[1] 

a(1)^{2} 
+ 
b(1) 
+ 
c 
= 
i 

[2] 

a(2)^{2} 
+ 
b(2) 
+ 
c 
= 
j 

[3] 

a(3)^{2} 
+ 
b(3) 
+ 
c 
= 
k 

We rewrite those equations slightly: 
[4] 

a^{} 
+ 
b 
+ 
c 
= 
i 

[5] 

4a 
+ 
2b 
+ 
c 
= 
j 

[6] 

9a 
+ 
3b 
+ 
c 
= 
k 

Subtract equation [4] from equation [5], giving us a new equation [7]: 

[5] 

4a 
+ 
2b 
+ 
c 
= 
j 
— 
[4] 

a^{} 
+ 
b 
+ 
c 
= 
i 


[7] 

3a 
+ 
b 


= 
j – i 
Subtract equation [5] from equation [6], giving us a new equation [8]: 

[6] 

9a 
+ 
3b 
+ 
c 
= 
k 
— 
[5] 

4a 
+ 
2b 
+ 
c 
= 
j 


[8] 

5a 
+ 
b 


= 
k – j 
Subtract equation [6] from equation [7], giving us a new equation [9]: 

[8] 

5a 
+ 
b 


= 
k – j 
— 
[7] 

3a 
+ 
b 


= 
j – i 


[9] 

2a 




= 
(k– j) –(j – i) 
Simplify the righthand side of [9]: 
Divide both sides of [10] by 2: 
Equation 11 gives us the formula for coefficient a. Now we take equation 7:
and move some of the terms from left to right: 
and that's the formula for coefficient b. To get c, we go back to equation [4]: 
Move some of the terms from left to right: 
And that's the formula for the last coefficient. 

Footnote
*You'll get a different answer depending on which three numbers you pick. The answers all generate the sequence, but they differ in that each one gives your first number when you plug n = 1 into the formula. In other words, for the result shown here, n = 1 gives 21. If you want n = 1 to give 1, the beginning of the sequence as shown above, you need to choose 1, 2, 21 as your three numbers. 









Summary
Here are the formulas for the coefficients. Given three adjacent numbers in a quadratic sequence i, j, and k:

a 
= 


b 
= 
j – i – 3a 

c 
= 
i – a – b 


Here's how you could implement these formulas in C++:
// Note: This simple implementation only works when the
//
sequence is quadratic with integer coefficients.
// If that's not the case, it gives unpredictable results.
void sequence_to_coefficients ( int &a, int &b, int &c,
int i, int j, int k )
{
a = ( i  2*j + k ) / 2;
b = j  i  3*a;
c = i  a  b;
}
// here's how you would call that function, using the three
// numbers we chose as examples in the text above
void my_code ()
{
int a, b, c; // the coefficients
sequence_to_coefficients ( a, b, c, 21, 58, 113 );
// now we know the coefficients. Here's how to calculate the
// value of the sequence for n = 8:
int y = a * 8 * 8 + b * 8 + c;
} 










