Hoping to check some recurrance relationship like this
$a_1 = x$ and $a_2 = y$, with
$$ a_{2n+1} = a_{2n} a_{2n-1} $$
and
$$ a_{2n+2} = a_{2n+1} + 4 $$
Tried
a[1] = x;
a[2] = y;
a[2*n + 1] := a[2*n]*a[2*n - 1];
a[2*n + 2] := a[2*n + 1] + 4
Table[a[n],{n,1,10}]
and
RecurrenceTable[
{a[2 n + 1] == a[2 n]*a[2 n - 1],
a[2 n + 2] == a[2 n + 1] + 4,
a[1] == x,
a[2] == y
},
a, {n, 1, 10}]
Neither works. How should I deal with the sub-index problem? Or am I defining it wrong?
I just hope to get the same result as
a[1] = x;
a[2] = y;
Do[
a[2*n + 1] = a[2*n]*a[2*n - 1];
a[2*n + 2] = a[2*n + 1] + 4;,
{n, 1, 10}
]
Table[a[n] // Expand, {n, 1, 10}]
{x, y, x y, 4 + x y, 4 x y + x^2 y^2, 4 + 4 x y + x^2 y^2, 16 x y + 20 x^2 y^2 + 8 x^3 y^3 + x^4 y^4, 4 + 16 x y + 20 x^2 y^2 + 8 x^3 y^3 + x^4 y^4, 64 x y + 336 x^2 y^2 + 672 x^3 y^3 + 660 x^4 y^4 + 352 x^5 y^5 + 104 x^6 y^6 + 16 x^7 y^7 + x^8 y^8, 4 + 64 x y + 336 x^2 y^2 + 672 x^3 y^3 + 660 x^4 y^4 + 352 x^5 y^5 + 104 x^6 y^6 + 16 x^7 y^7 + x^8 y^8}