# RecurrenceTable with vectors

Is there a way to call parts of a vector in RecurrenceTable? This does not work:

RecurrenceTable[{n[t + 1] == {n[t][]}, n == {0}}, n, {t, 1, 3}]

(* Out= RecurrenceTable[{n[1 + t] == {t}, n == {0}}, n, {t, 1, 3}] *)


I would like to keep the vector structure because the original problem should be expanded to more dimensions.

ps: The original problem is

a[x_] := {{0, 2/(1 + x)}, {.8, .2}};
RecurrenceTable[{n[t + 1] == a[n[t][]].n[t],n == {0, 1}}, n, {t, 1, 25}]

During evaluation of In:= Part::partw: Part 2 of n[t] does not exist.


what does not run because apparently also in this example the "Part" command is executed before the RecurrenceTable.

• Have you tried Indexed instead of Part? Nov 13 '16 at 14:48
• @Michael E2 is correct: RecurrenceTable[{n[t + 1] == a[Indexed[n[t], 2]].n[t], n == {0, 1}}, n, {t, 1, 10}]' seems to work fine. Nov 13 '16 at 15:20
• @Michael E2, thank you, that's perfect. I like the solution with Indexed because the code stays clear. Nov 14 '16 at 18:57

RecurrenceTable works fine with vectors. Here's an example:

a = {{1, 2}, {1, 3}};
RecurrenceTable[{n[t + 1] == a.n[t], n == {1, 1}}, n, {t, 1, 3}]


It returns the first three vectors.

For your specific problem, I would program it directly using recursions (rather than using RecurrenceTable, since you have greater control). Here is one possible implementation where I have replaced your vector n with the pair {n,m}.

a[x_] := {{0, 2/(1 + x)}, {.8, .2}};
n[t_] := (a[(m[t - 1])].{n[t - 1], m[t - 1]})[];
m[t_] := (a[(m[t - 1])].{n[t - 1], m[t - 1]})[];
{n, m} = {1, 2};


Now you can evaluate any given values:

{n, m}
{1.33333, 1.2}


or evaluate a range:

{n[#], m[#]} & /@ Range
`
• Yes that works, but how can you call single parts of the vector in the RecurrenceTable? See the example in the ps. part of the question. Nov 13 '16 at 10:56