# Solving linear recursions without constant depth in mathematica

Mathematica does not like this recurrence relation. I do not understand why?

RSolve[{a == 1,
a[n] == 2 + 2 a + 2 Sum[a[i], {i, 1, n - 2}] + a[n - 1],
a == 3, a == 7}, a, n]
Table[a[n] /. First[%], {n, 10}]


If I change the 1 in the sum to n-3 or something, that it seems to be okay. But why can't I sum from 1 to n-2?

• Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) 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! 3) As you receive help, try to give it too, by answering questions in your area of expertise. Feb 28, 2015 at 23:45

a = 1;
a = 3;
a = 7;
a[n_] := If[n >= 3, 4 + 2 Sum[a[i], {i, 1, n - 2}] + a[n - 1]];
Table[a[n], {n, 0, 10}]


(* {1, 3, 7, 17, 41, 99, 239, 577, 1393, 3363, 8119} *)

FindSequenceFunction[Table[a[n], {n, 0, 10}]]


(* 1/2 ((1 - Sqrt)^#1 + (1 + Sqrt)^#1) & *)

• Array[a, 11, 0] would be shorter than Table. +1 however. Mar 1, 2015 at 0:33
• @Mr.Wizard Ah yes. I started by editing the posers code, including the Table, whereas Array would be just a bit cleaner. Mar 1, 2015 at 0:38

Just another way to generate sequence:

in = {1, 3, 7};
f = {##, 2 Total@Most@{##2} + 4 + Last@{##}} &;


Now you can generate sequence of desired length, e.g. a,...,a (8 extra elements)

Nest[f@@#&,in,8]


yielding: {1, 3, 7, 17, 41, 99, 239, 577, 1393, 3363, 8119}

or define function:

a := 1;
a := 3;
a := 7;
a[n_] := Last@Nest[f @@ # &, in, n - 2]


and use, e.g, FindSequenceFunction[Nest[f @@ # &, in, 10]] as David G, Stork.

This is just another way and I have voted +1 David G. Stork.