# RecurrenceTable with vector

Mathematica can do a RecurrenceTable with a vector, here is a simple example:

RecurrenceTable[{x[n + 1] == 2* x[n], x == {1, 2, 3}}, x, {n,  3}]


with output

{{1, 2, 3}, {2, 4, 6}, {4, 8, 12}, {8, 16, 24}}

I want to do something similar but instead of multiplying by 2 I want to multiple each element in x[n] by a different number. For example, one would think that this would work:

RecurrenceTable[{x[n + 1] == {1,2,3}* x[n], x == {1, 2, 3}}, x, {n,  3}]


since Times is listable but I get an error

RecurrenceTable::excptn: Value {1,2,3,2,4,6,3,6,9} is a numerical exception. >>

I get the same result using MapThread etc. Thoughts?

• Would NestList[{1, 2, 3} # &, {1, 2, 3}, 3] be acceptable ? – b.gates.you.know.what Jan 8 '13 at 19:00
• Try to write down your recurrence formulae ... – Dr. belisarius Jan 8 '13 at 19:12
• Although you say you see the same problem "using MapThread", in MMA 8 this succeeds: RecurrenceTable[{x[n + 1] == MapThread[Times, {{1, 2, 3}, x[n]}], x == {1, 2, 3}}, x, {n, 3}]. (This expression was prompted by @b.gatessucks' answer.) – whuber Jan 8 '13 at 21:00

The trick below seems to work in this simple case :

g[input_List] := {1, 2, 3} input

RecurrenceTable[{x[n + 1] == g[x[n]], x == {1, 2, 3}}, x, {n, 3}]
(* {{1, 2, 3}, {1, 4, 9}, {1, 8, 27}, {1, 16, 81}} *)

• (+1) The truly curious thing about this work-around is if you merely leave List out of the definition of g, the RecurrenceTable expression does not work (it returns an empty list). Tracing the evaluation reveals the problem: {1,2,3}*x[n] is expanded as {x[n], 2 x[n], 3 x[n]}, because MMA does not (yet) know that x[n] is a list at the time of expansion. – whuber Jan 8 '13 at 20:51
• @whuber That was the whole trick ! – b.gates.you.know.what Jan 8 '13 at 21:00
• And a nice trick it is. :-) – Mr.Wizard Jan 8 '13 at 22:18
• Thanks. All the comments have been very helpful! – Alex Jan 9 '13 at 15:18

Not sure what the policy is on reviving dead threads, but I came across this after a similar problem and realized that RecurrenceTable works with vectors if you treat the equations with proper matrix calculations. e.g.

RecurrenceTable[{
x[n + 1] == {{1, 0, 0}, {0, 2, 0}, {0, 0, 3}}.x[n],
x == {1, 2, 3}
}, x, {n, 3}]


gives the correct result without any intermediate functions:

{{1, 2, 3}, {1, 4, 9}, {1, 8, 27}, {1, 16, 81}}