1
$\begingroup$

Why doesn't this work:

p = {1,2,3};
Manipulate[{p[[1]], p[[2]], p[[3]]}, {p[[1]], 0, 1}, {p[[2]], 0, 1}, {p[[3]], 0, 
      1}]
"Manipulate argument {p[[1]],0,1} does not have the correct form for \
a variable specification"

Neither this:

Manipulate[{Indexed[p, 1], Indexed[p, 2], 
  Indexed[p, 3]}, {Indexed[p, 1], 0, 1}, {Indexed[p, 2], 0, 
  1}, {Indexed[p, 3], 0, 1}]

and how do I use lists in Manipulate w/o stupid hacks like p[i] and then iterating over it with For?

$\endgroup$
4
  • $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour (mathematica.stackexchange.com/tour) now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$
    – LouisB
    Jul 28, 2021 at 9:01
  • $\begingroup$ Did you try this? ClearAll[p]; Manipulate[{p[1], p[2]}, {p[1], 0, 1}, {p[2], 0, 1}] $\endgroup$
    – LouisB
    Jul 28, 2021 at 9:04
  • $\begingroup$ @LouisB yes, and I have mentioned that in my question. I then have to collect all those p[1],p[2]... into a list for further processing, which is unhandy. Mathematica is all about lists as I see, so why there's no simple way to use them with Manipulate? $\endgroup$
    – wolfRAMM
    Jul 28, 2021 at 9:14
  • $\begingroup$ You may get better answers if you edit your question to describe what you are trying to achieve. $\endgroup$
    – LouisB
    Jul 28, 2021 at 9:28

2 Answers 2

1
$\begingroup$

The correct answer is to use nested With as shown below. Note that the hack i=i is mandatory, and you can't tmp[[i]]=# because you would get Set::setps: {FE` $1462$$530,FE`$1463$$530,FE`$1464$$530} in the part assignment is not a symbol.

ClearAll[p, list, tmp];
list = {1, 2, 3};
MakeTable[] := Table[p[i], {i, 1, Length@list}];
With[{vars = MakeTable[],
  controls = Sequence @@
    Table[{p[i],
      list[[i]],
      With[{i = i, tmp = MakeTable[]},
       (Slider[Dynamic[tmp[[i]],
           (tmp = 
              Normal@SparseArray[
                Join[{i -> #}, 
                 Table[j -> list[[j]], {j, 1, Length@list}]]]; 
             list = tmp) &], {0, 10}]) &]},
     {i, 1, Length@list}]},
 {Manipulate[vars, controls], Dynamic@list}]

manipulate a list

$\endgroup$
0
$\begingroup$

As mentioned in comments, it's not clear what you're trying to do.

You're getting an error because p={1,2,3} is a list of numbers. Essentially you have Manipulate[1,{1,0,1}]. 1 is not a variable so you can't range over it, i.e. {1,0,1} makes no sense. It needs to be in the form Manipulate[expr,{u,umin,umax}]. See Manipulate.

enter image description here

If you do Manipulate[{x,y,z},{x,0,1},{y,0,1},{z,0,1}] it will work, but you just get three sliders that vary the output point, so I don't really see the purpose of that. Having {x,y,z} as the expression input expr is pretty boring.

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.