# Getting the first $n$ terms of a recursion relation

Given a recursion relation, I would like to generate the first $n$ terms (automatically) without having to go term by term.

Background

Each term is of the form $a_{n}(t)$, that is, $a_{n}$ is a function of $t$. However, $t$ does not appear explicitly - it appears as $f(t)$, where $f$ is an arbitrary function of $t$. As such, the recurrence contains the times derivatives of $a_{n}(t)$ and $f(t)$.

We are given the first term, namely, $a_{0}(t)=1$.

In Mathematica, to compute $a_{1}(t)$, I do the following:

n=1;

a[0][t]=1;

Solve[(n + 1) (n - 4) (6 - n)*a[n][t]*D[f[t], t] ==
-(n - 3) (n - 4)*D[a[n - 1][t], t] +
12*Sum[D[a[k][t], t]*a[n - 1 - k][t], {k, 0, n - 1}] -
12*Sum[(k - 2)*a[k][t]*a[n - k][t]*D[f[t], t], {k, 1, n - 1}],
a[n][t]]

This gives $a_{1}(t)=0$. To compute the next term $a_{2}(t)$ I manually update the value of $n$ to $n=2$ and add the value of $a_{1}(t)$ together with $a_{0}(t)$.

n=2;
a[0][t]=1;
a[1][t]=0;

Solve[(n + 1) (n - 4) (6 - n)*a[n][t]*D[f[t], t] ==
-(n - 3) (n - 4)*D[a[n - 1][t], t] +
12*Sum[D[a[k][t], t]*a[n - 1 - k][t], {k, 0, n - 1}] -
12*Sum[(k - 2)*a[k][t]*a[n - k][t]*D[f[t], t], {k, 1, n - 1}],
a[n][t]]

I repeat the same procedure to find $a_{3}(t)$ and so on. This approach is quite tedious. Is there a way of generating the terms automatically instead of relying on the manual approach?

• a[3] gives you zero. There is no solution for a[4] ... recheck your equations – Dr. belisarius Mar 17 '15 at 4:58
• The left hand side has the factor $(n+1)(n-4)(6-n)$ which becomes 0 for $n=4$ and $n=6$. Now, for $n=4$ the right hand side (which can be worked out because we know the previous values of $a_{n}(t)$) is also 0. This means that $a_{4}(t)$ is a free parameter. Similarly, $a_{6}(t)$ will turn out to be also a free parameter. Should I add this to the question? Thanks. – Jack Mar 17 '15 at 5:09
• Welcome to Mathematica.SE! I suggest the following: 0) Browse the common pitfalls question 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Dr. belisarius Mar 17 '15 at 5:43
• @m_goldberg, Thanks for the edit (and the upvote). I can now start upvoting too :-). – Jack Mar 17 '15 at 11:14

Not sure if this is what you want. Anyway:

a[0][t] = 1;
sol[4] = {a[4][t] -> a[4][t]}
sol[6] = {a[6][t] -> a[6][t]}
sol[n_] := sol[n] = First@Solve[
(n + 1) (n - 4) (6 - n)*a[n][t]*
D[f[t], t] == -(n - 3) (n - 4)*D[a[n - 1][t], t] +
12*Sum[D[a[k][t], t]*a[n - 1 - k][t], {k, 0, n - 1}] -
12*Sum[(k - 2)*a[k][t]*a[n - k][t]*D[f[t], t], {k, 1, n - 1}],
a[n][t]]

Table[a[n][t] = (a[n][t] /. sol[n]), {n, 1, 12}]

$\begin{array}{l} 0 \\ 0 \\ 0 \\ a(4)(t) \\ \frac{5 a(4)'(t)}{3 f'(t)} \\ a(6)(t) \\ 0 \\ \frac{1}{3} (a(4)(t))^2 \\ \frac{2 a(4)(t) a(4)'(t)}{3 f'(t)} \\ \frac{18 a(4)(t) a(6)(t) f'(t)^2+25 \left(a(4)'(t)\right)^2}{66 f'(t)^2} \\ \frac{a(6)(t) a(4)'(t)}{3 f'(t)} \\ \frac{1}{39} \left(2 (a(4)(t))^3+3 (a(6)(t))^2\right) \\ \end{array}$

• Thank you very much. I can easily find out which parameters are free without using Mathematica. So, this works perfectly for my case. – Jack Mar 17 '15 at 5:38