# Entering exogenous data in a RecurrenceTable

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.)

• 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}]. Commented Jun 24 at 22:24
• 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?
– Alan
Commented Jun 24 at 23:16
• You could do what @ydd showed below, or something like: eVals = {1, 3, 10}; e[n_?NumericQ] := eVals[[n]]; Commented Jun 25 at 14:20

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


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


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];