I recently lost a lot of time on this and need to understand whether I have misunderstood MMA operations or there's a problem. I am using MMA 10.1 on Windows 7 64-bit.
The essence of the issue is this: I believed that Table, RecurrenceTable etc, per the description of Table in the documentation, localise the iterating variable, and thus that using e.g. "i" in a RecurrenceTable and elsewhere in a notebook for some other purpose should not cause a conflict.
(Related question: ParametricPlot iterator not "block"-ed)
However as the three cases below show, unless the iterating variable is not reused or explicitly shielded by e.g. a Module in a definition incorporating a RecurrenceTable, I get the error that "1", "2", etc. cannot be used as a variable.
Sample code follows (with forced clear for safety). The first two definitions of logisticMap cause no problems in subsequent use, but when the subsequent use reuses an unshielded iterating variable the error occurs.
Clear[Evaluate[Context[] <> "*"]]
1st def: OK (i as a module variable in RecurrenceTable, and i in For[])
logisticMap[x0_, μ_, n_] :=
Module[{i},
RecurrenceTable[{x[i + 1] == μ x[i] (1 - x[i]), x[1] == x0},
x, {i, 1, n}]]
pRow = {};
dataSeries := logisticMap[0.1, 3.55, 10];
For[i = 1, i <= 10, i++, AppendTo[pRow, dataSeries[[i]]]];
2nd def: OK (use b as iterator for RecurrenceTable and i in For[])
logisticMap[x0_, μ_, n_] :=
RecurrenceTable[{x[b + 1] == μ x[b] (1 - x[b]), x[1] == x0},
x, {b, 1, n}]
pRow = {};
dataSeries := logisticMap[0.1, 3.55, 10];
For[i = 1, i <= 10, i++, AppendTo[pRow, dataSeries[[i]]]];
3rd def: error (i as unshielded iterator in RecurrenceTable, and in For[])
logisticMap[x0_, μ_, n_] :=
RecurrenceTable[{x[i + 1] == μ x[i] (1 - x[i]), x[1] == x0},
x, {i, 1, n}]
pRow = {};
dataSeries := logisticMap[0.1, 3.55, 10];
For[i = 1, i <= 10, i++, AppendTo[pRow, dataSeries[[i]]]];
The error being
RecurrenceTable::dsvar: 1 cannot be used as a variable. >> etc.
a) What exactly is happening (why is "1" being used as a variable) and
b) Is this user error or a bug (that I would then report)?
[BTW Do you think Wolfram would respond +vely to a request for a free upgrade if this is a bug as this is a seriously undermining issue AND I am still suffering from an unresolved startup issue in 10.1?]
Thanks,
Comments
Post a Comment