TITLE: Relation between differential equations and sequence recursions
QUESTION [8 upvotes]: It's obvious that there is a strong relation between linear recursions of sequences and linear differential equations. The common methods for solving them are nearly identical. For example, the general solution to
$$ a_{n+2} = 5 a_{n+1} - 6 a_n + 2^n (4n - 2) $$
is 
$$a_n = 3^n A - 2^n (n^2 + 2n + B)$$
with arbitrary constants $A$ and $B$; if $a_0 = 1$ and $a_1 = 2$ were given, 
$$a_n = 6 \cdot 3^n - 2^n (n^2 + 2n + 5)$$
would be the only solution. In terms of differential equations, the general solution to 
$$ \frac{d^2y}{dx^2} - 5 \frac{dy}{dx} + 6 y = e^{2x} (4x - 2) $$
is 
$$y(x) = e^{3x} A - e^{2x} (2x^2 + 2x + B),$$
or, if $y(0) = 1$ and $y'(0) = 2$ are given, 
$$y(x) = 2  \cdot e^{3x} - e^{2x} (2x^2 + 2x + 1).$$
There are some major parallels, but there are also differences. While I know why this basically works, i.e., that raising $n$ by one does the same thing to $n^3$ as differentiating with respect to $x$ does to $e^{3x}$, my question is: Is there an underlying connection between these two equations, something I missed? Or is it just that, that they have some similar properties?

REPLY [4 votes]: There is indeed a deep connection between the two equations, that is the starting point for the theory of generating functions.
The connection is given by the following one-on-one correspondence between real-valued sequences and powerseries
$$i \colon \mathbb R^{\mathbb N} \longrightarrow \mathbb R[[x]]$$
$$i((a_n)_n) = \sum_{n \in \mathbb N} \frac{a_n}{n!}x^n$$
which is an isomorphism between these $\mathbb R$-vector spaces.
By using this isomorphism backward you can endow the space of sequences with a product, defined as $(a_n)_n \cdot (b_n)_n=(\sum_{k=0}^n a_k b_{n-k})_n$, and a derivation operator, which coincides with the shifting operator: $\frac{d}{dx}((a_n)_n)=(a_{n+1})_n$ (it is an easy count to verify that $i\left(\frac{d}{dx}(a_n)_n\right)=\frac{d}{dx}i(a_n)_n$).
You can think of a recursive equation as a sequence of equations, parametrized by the index $n$, that you can fuse into a equation whose terms are expressions build up from sequences using sum, multiplication, scalar multiplication and the shifting/derivator operator.
For instance from recursive equation in your question  you can get the following equation
$$\frac{d^2}{dx^2}(a_n)_n=5\frac{d}{dx}(a_n)_n -6 (a_n)_n+4(2^nn)_n-2(2^n)_n$$
which through the isomorphism $i$, by letting $y=i(a_n)_n$, becomes 
$$\frac{d^2}{dx^2}y=5\frac{d}{dx}y-6y+4e^{2x}-2e^{2x}$$
that is the differential equation in you question.
Since these two equations correspond through the isomorphisms $i$ the solutions of the equations correspond one to each other through $i$ too: if $(a_n)_n$ is a solution to the sequence-equation then $i(a_n)_n$ is a solution to the differential equation.
For instance if you take the solution $a_n=6\cdot 3^n-2^n(n^2+2n+5)$ then $$i(a_n)_n = 6e^{3x}-e^{2x}(x^2+2x+5)\ .$$
There could be so much more to say about generating functions but I am afraid that would take us too far from the scope of the question.
I hope this helps.