2
$\begingroup$

This is a very simple question but I couldn't find it in the documentation; if it's there, kindly point it out.

I want to define a Recurrence Table for the iteration x[n+1]=a*x[n] + E[n], where E[n] is a series of numbers I've entered separately {E[1],E[2],...}. What is the syntax for doing this? (i.e, once the rest of RecurrenceTable command is included - initial condition, etc.)

$\endgroup$
3
  • $\begingroup$ I'm not sure what's bothering you. You can do exactly what you've written, for example: e[1]=1;e[2]=3;e[3]=10; RecurrenceTable[a[n+1]==2a[n]+e[n]&&a[1]==0,a[n],{n,1,4}]. $\endgroup$
    – Domen
    Commented Jun 24 at 22:24
  • $\begingroup$ Thanks for your reply. I have a list of about 35 numbers; do I have to write them this way one-by-one or can I enter them a a list and have RecurrenceTable read from that? $\endgroup$
    – Alan
    Commented Jun 24 at 23:16
  • $\begingroup$ You could do what @ydd showed below, or something like: eVals = {1, 3, 10}; e[n_?NumericQ] := eVals[[n]]; $\endgroup$
    – Domen
    Commented Jun 25 at 14:20

1 Answer 1

3
$\begingroup$

One possibility is to use FoldList. As a short symbolic example:


eList = Array[e, 3];
FoldList[a #1 + #2 &, x[1], eList]

![enter image description here

Or if you prefer a numeric example:

eList = Range[3];
a = 2;
x[1] = 0;
FoldList[a #1 + #2 &, x[1], eList]

(*{0, 1, 4, 11}*)

Another option (though I have a feeling this could be a dangerous idea for some reason) is to MapThread Set across a range of e[i] for some given values and use RecurrenceTable:

ClearAll[e];
eList = Array[e, 3];
eVals = Range[3];
MapThread[Set, {eList, eVals}];
RecurrenceTable[x[n + 1] == 2 x[n] + e[n] && x[1] == 0, 
 x[n], {n, 1, 4}]
(* {0, 1, 4, 11} *)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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