<s>[INST] Finding the function for a sequence using differences I am trying to find a function generating/suitable for the following sequence:
${2,6,12,20,30,42,56...}$
The first order differences are:
$4, 6, 8, 10, 12, 14...$
and the second order differences are:
$2, 2, 2, 2, 2, 2...$
this means that:
$y''= 2 \implies y' = 2\cdot x + c$ and we can see that for $c = 2$ we can get the correct numbers i.e. the first order differences (replacing starting from $x = 1$). So $y' = 2\cdot x + 2$
This means that $y = x^2 + 2\cdot x + c$
But I can't find any value of $c$ that would give the original sequence.
Now I see that $y'$ could also be $y' = 2\cdot x + 4$ as it gives the correct numbers if we replace starting from $x = 0$ but then we have $y = x^2 + 4\cdot x + c$ and I again can't find any $c$ that matches the original sequence.
What am I doing wrong here?
 [/INST] Let $\{a_n\}_{n\in\mathbb N}=\{2,6,12,20,30,42,56,\ldots\}$. Let $\{b_n\}_{n\in\mathbb N}$ be the sequence of the first-order forward differences of $\{a_n\}$, and $\{c_n\}_{n\in\mathbb N}$ the sequence of second-order differences. So for $n\ge1$,
$$b_n = a_{n+1} - a_n \\ c_n = b_{n+1} - b_n$$
As you observed, $c_n=2$ for all $n$. Then
$$\begin{align*}b_{n+1} &= b_n + 2 \\
&= b_{n-1}+2\times2 \\
&= b_{n-2}+3\times2 \\
&~~\vdots \\
&= b_1 + 2n
\end{align*}$$
which means $b_n = b_1+2(n-1)=2(n+1)$.
Now solve for $a_n$:
$$\begin{align*}
a_{n+1} &= a_n + 2(n+1) \\
&= a_{n-1} + 2((n+1) + n) \\
&= a_{n-2} + 2((n+1) + n + (n-1)) \\
&~~\vdots \\
&= a_1 + 2 \sum_{k=0}^{n-1} (n+1-k)\\
&= a_1 + n^2 + 3n
\end{align*}$$
so that $a_n = 2 + (n-1)^2 + 3(n-1) = n^2 + n$.
In case you are interested in the generating function, it takes the form
$$f(x) = \sum_{n=0}^\infty a_n x^n$$
Recall that if $|x|<1$, we have
$$\frac1{1-x} = \sum_{n=0}^\infty x^n$$
and finding $f(x)$ is just a matter of differentiating both sides twice.
$$\frac1{(1-x)^2} = \sum_{n=0}^\infty nx^{n-1} = \sum_{n=1}^\infty nx^{n-1} = \sum_{n=0}^\infty (n+1)x^n$$
$$\frac2{1-x^3} = \sum_{n=0}^\infty (n^2+n) x^{n-1}$$
$$\implies f(x) = \frac{2x}{1-x^3} = \sum_{n=0}^\infty (n^2+n) x^n$$
</s>