Well, I cracked that.
Summary
- Avoid using n[1], n[2],... as variable names. n1, n2,... work for the assignment. n[1],n[2],... do not
- Achieve an additional level of evaluation "hold" using strings and
ToExpression
to get back the expression.
- Make the variables of Manipulate global using
LocalVariables->False
option
- Perform the assignment to the vector OUTSIDE
Manipulate
using Dynamic.
All of this is required to achieve one goal - set the number of variables in a scalable manner, rather than typing is by hand
So, the solution goes as follows
Clear[v]; Clear["Global`n*"];
(* The last Clear is required for repeated experiments, the first is not essential *)
ivars = Sequence @@ Array[{Symbol["n" <> ToString[#]], 0, 1} &, 5] (*set of variables + their range for manipulate *)
vars = Array[Symbol["n" <> ToString[#]] &, 5] (* the variables to be used in the body of manipulate and the assignment *)
Finally the line
{Manipulate[Evaluate@vars, Evaluate@ivars,
LocalizeVariables -> False], Dynamic[v = vars]}
does the work.
I managed to clear them using strings and ToExpression
so Mathematica developers probably are facing the same issue. I would expect a better sort of Hold
behavior, but this is what we have...
Hope this helps.
yehuda