0
$\begingroup$

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

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

(* Out[1]= RecurrenceTable[{n[1 + t] == {t}, n[1] == {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][[2]]].n[t],n[1] == {0, 1}}, n, {t, 1, 25}]

During evaluation of In[1]:= 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.

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

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

a = {{1, 2}, {1, 3}};
RecurrenceTable[{n[t + 1] == a.n[t], n[1] == {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]})[[1]];
m[t_] := (a[(m[t - 1])].{n[t - 1], m[t - 1]})[[2]];
{n[1], m[1]} = {1, 2};

Now you can evaluate any given values:

{n[2], m[2]}
{1.33333, 1.2}

or evaluate a range:

{n[#], m[#]} & /@ Range[10]
$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – tukan
    Nov 13 '16 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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