

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer

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.

share|improve this question
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 :… – 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
up vote 8 down vote accepted

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


Out[3]= 2^n E^(2 x)
share|improve this answer
+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. – Dr. 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):

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]]];

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[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]

There are your closed forms.

share|improve this answer
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
In most cases, there's no such thing, @Murray. Examples are the classical functions of mathematical physics: the polynomials of Hermite, Lagrange, Chebyshev, Laguerre, Legendre, etc. Usually these have to be found via recursion rather than in closed form or if not, it's still simpler just to use the recursion (and other relationships among the polynomials). When you look at general differential-difference equations the situation gets even worse. – whuber Apr 24 '12 at 19:49
@whuber Thanks, that is certainly helpful to see more sophisticated syntax than I know. murray is correct that I'm looking for closed form for all n simultaneously. Sure, such answers are rare. But if my equation could expressed, say, in terms of one of these classic families, it would be nice if Mathematica could tell me that. I was hoping that I could at least ask Mathematica to try. But your point that it's simpler to just work with the recursion is well taken. – UVW Apr 24 '12 at 19:59
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
@whuber: yes, I'm well aware of the limitations on finding closed-form expressions (at least in terms of functions that are "elementary" in the technical sense of the term)! It was the O.P. who asked about such. – murray Apr 25 '12 at 0:12

Your Answer


