However, all attempts to use a more generalized approach, i.e. to assign values input by “Manipulate” to the components of the vector: parameter1[i] for {i,1,k} fail (even if I assign a fixed value to k).
Any help appreciated - and … apologies if this is
Thank you very much for your swift support. However, your solution assigns the second vector to the first, but not ist value. I.e. afer selection parameter1[4]=n[4] but not the value/number chosen for n[4].
This is merely a beginner’s problem
When you define a variable for Manipulate it accepts a different name (eg. $471 etc.)
Whenever you try to generate such a name (using do, Table, Array etc.) (rather than write it explicitly) the generation works but not with the local name.
However, this does not solve the second issue of assigning the value to the vector. I checked all the possibilities that I’m aware of. This happens since the assignment is applied immediately, therefore the right hand side of the assignment is not getting the values of n[1], (unless of course, u
you use the names of the variables explicitly, and then you do not have a problem in the first place…)
If I’ll find a way , I’ll publish it later
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 *)
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…