# How can I solve a difference-differential equation?

How do I ask Mathematica to try to solve a recursive relation that defines a sequence of functions? For example, suppose I know that $g_n(x) = g_{n-1}'(x)$ for $n > 0$ and that $g_0(x) = e^{2x}$. How can I ask Mathematica to find a closed form for $g_n(x)$? (This is just a placeholder equation to highlight my question; I know the answer of $g_n(x) = 2^n e^{2x}$, $n\geq 0$.)

A less trivial instance of the problem would be the Hermite polynomial recursion, $$H_{n+1}(x) = 2xH_n(x) - H_n'(x)$$

I don't see how to convince either DSolve or RSolve to solve it for me. DSolve is unhappy because $n-1$ is used on the RHS:

DSolve[{g[n, x] == 2*D[g[n - 1, x], x]}, g, {n, x}]


RSolve just echoes my input:

RSolve[{g[n, x] == 2*D[g[n - 1, x], x], g[0, x] == Exp[2*x]}, g, {n, x}]


I know finding a closed-form solution is going to be hopeless in most instances, but it seems like some cases like the above $g_n(x)$ should be doable. I have been unable to find any examples in the Mathematica documentation addressing this type of problem.

-
Are you looking for a closed form solution in terms of $n$, or you just want to compute the result for each $n$ successively? –  Szabolcs Apr 24 '12 at 15:38
You may look here, for recursive definitions of Hermite polynomials : mathematica.stackexchange.com/questions/4652/… –  Artes Apr 24 '12 at 15:42
I tried Solve[{Series[g[n, x], {x, 0, 5}, {n, 0, 5}] == Series[2*D[g[n - 1, x], x], {x, 0, 5}, {n, 0, 5}]}, g, {n, x}] but didn't found the solution. I think you will try to search a closed form asymptotically. –  GarouDan Apr 24 '12 at 16:33
@Szabolcs I'm looking for closed forms. I know that g=Table[0,{t,0,10}]; g[[1]]=Exp[2*x]; Table[g[[i+1]]=D[g[[i]],x],{i,1,9}] will compute the result (I'm sure there are more elegant ways). Artes Thanks. I'm more interested in how to deal with this paradigm rather than Hermite polynomials in particular. –  UVW Apr 24 '12 at 17:01

For the simple example in the question, FindSequenceFunction can be used to infer the general form:

g[0]=Exp[2x];
g[n_]:=g[n]=Expand[D[g[n-1],x]]

FindSequenceFunction[g/@Range[5],n]
Out[3]= 2^n E^(2 x)

-
+1 Really nice. The sentence For the simple example in the question should not be taken lightly, as FindInstance is not able to find many "easy" sequences. –  belisarius Apr 24 '12 at 21:53
Thanks, @Simon. It was probably unreasonable of me to hope for more. This looks like a reasonable approach. –  UVW Apr 25 '12 at 16:35

This is recursion, not solution-finding. That makes it fast and straightforward. For instance, the Hermite polynomial example, with memoization of the function (not just of its values at previous arguments of $x$), might look like this (although I'm sure the real experts can find a more elegant way to accomplish the same thing):

ClearAll[g];
g[n_Integer, x_] := g[n][x];
g[0] = Function[{x}, 0];
g[1] = Function[{x}, 1];
g[n_Integer][x_] := With[{},
g[n] = Function[{y}, Evaluate@ Expand[2 y g[n - 1, y] - D[g[n - 1, y], y]]];
g[n][x]
]


After executing, say,

In[2]:= g[5,x]
Out[2]= 12 - 48 x^2 + 16 x^4


the definition of g will be

? g

g[n_Integer][x_]:=With[{},g[n]=Function[{y},Evaluate[Expand[2 y g[n-1,y]-\!$$\*SubscriptBox[\(\[PartialD]$$, $$y$$]$$g[n - 1, y]$$\)]]];g[n][x]]

g[0]=Function[{x},0]
g[1]=Function[{x},1]
g[2]=Function[{y$},2 y$]
g[3]=Function[{y$},-2+4 y$^2]
g[4]=Function[{y$},-12 y$+8 y$^3] g[5]=Function[{y$},12-48 y$^2+16 y$^4]
g[n_Integer,x_]:=g[n][x]


Those are just closed-forms for particular values of $n$. I thought the O.P. wanted a closed-form expression as a function of $n$ (and $x$, of course). –  murray Apr 24 '12 at 19:34
OK, thanks for the clarification @UVW. Nevertheless, often a list of solutions can be a good start: you can then pick out the coefficients of the components of the solutions and search for closed forms using FindSequenceFunction and their ilk. Sometimes it works! –  whuber Apr 24 '12 at 20:14