Recursion without starting values

r[0] := r0; r[1] :=r1;
r[n + 1] := ar[n] + br[n - 1];
Table[r[n + 1], {n, -1, 12}]

all I get is only…

{r0, r1, r[2], r[3], r[4], r[5], r[6], r[7],
  r[8], r[9], r[10], r[11], r[12], r[13]}

but i need r[2], r[3], r[4] … r[13] depending on r0 and r1
for example:

r[2] = a b r0+ (a^2 + b) r1

thx for helping

Hi Harry Potter,

this is a simple difference equation which can be solved by Mathematica:

ClearAll["Global`*"]
sol = First @ RSolve[{r[n + 1] == a r[n] + b r[n - 1], r[0] == r0, r[1] == r1}, r[n], n];
r[n_, a_, b_] = Simplify[r[n] /. sol];
Table[r[n, a, b], {n, 0, 13}]

In case this is a homework problem the solution alone is by no means sufficient, you need to supply the intermediate calculations anyway. This can be done in an elegant way in analogy to the calculation of a closed form for Fiboncci numbers (“matrix form”).

Regards – Henrik

Hi,

what about this?

r[0] = r0; r[1] = r1; r[n_] := a r[n - 1] + b r[n - 2]; Table[r[x], {x, 0, 12}]

Cheers,

Marco

That was exactly what I needed. Thanks. Ta! ^^