0
$\begingroup$

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

RSolve[{a[0] == 1, 
  a[n] == 2 + 2 a[0] + 2 Sum[a[i], {i, 1, n - 2}] + a[n - 1], 
  a[1] == 3, a[2] == 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?

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – bbgodfrey
    Feb 28, 2015 at 23:45

2 Answers 2

4
$\begingroup$
a[0] = 1;
a[1] = 3;
a[2] = 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[2])^#1 + (1 + Sqrt[2])^#1) & *)

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

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[0],...,a[10] (8 extra elements)

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

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

or define function:

a[0] := 1;
a[1] := 3;
a[2] := 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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.