I'm trying to create a table whose elements will be a sum over previously declared elements up to a certain iteration. I've reduced what I'm trying to do to the simplest form (posted below):
M[x_] := M[x] = Table[
If[
n == 1, r, 2 x^n Sum[M[x][[i]], {i, 1, n-1}]
],
{n, 1, 5}]
When I evaluate the above expression, it produces an exceedingly long expression that is obviously wrong. What's the mistake that I'm making here?
M[x]
only references itself here, so it will be an infinite recursion. When you callM[1]
for instance, the RHS contains a sum over the elements ofM[1]
. $\endgroup$ – Marius Ladegård Meyer Mar 5 '16 at 23:14M[x]
is referenced it must call itself to determine its value.Table
must complete and return a value toM[x]
beforeM[x]
can be assigned a value. Since the looping is happening inside ofTable
the calls inTable
toM[x]
are causingM[x]
to be called again in a never ending loop. $\endgroup$ – Edmund Mar 5 '16 at 23:31RecurrenceTable[]
? $\endgroup$ – J. M.'s ennui♦ Mar 5 '16 at 23:52