Message Boards Message Boards

GROUPS:

How can I use in Manipulate an array of integers as an input?

Posted 3 months ago
496 Views
|
5 Replies
|
2 Total Likes
|

I want to use a list of integers in something like this:

Manipulate[
 Sum[i, {i, l}],
 {l}
 ]

Whithout having to use the brackets in the input field, i'd like to use 1,2,3 instead of {1,2,3}. Is that possible?

5 Replies
Posted 3 months ago

Hi Francesco,

Can you please clarify your question. There is no {1, 2, 3} in the posted code so it is not clear what exactly you are trying to replace.

Posted 3 months ago

Hi Rohit,

I'd like to use 1,2,3 instead of {1,2,3} in the input field below.

enter image description here

Posted 3 months ago

I'm taking a guess that you want to pass separate scalars to a function instead of putting those scalars into a list.

The Wolfram has the concept of sequences which can help. And fortunately, it is easy to switch between sequences and lists. For example, if I define a function as:

f[x : ___] := List[x];
f[x_List] := x;

Then, I can call this function with either:

f[1, 2, 3];
f[{1, 2, 3}];

And get the same result: {1, 2, 3}

If this isn't what you are talking about, please provide some more info.

THANKS

Posted 3 months ago

Thanks Mike, That's more or less what i'd like to do, but this behavior does not seem to transpose well into Manipulate expressions.. Or at least i did not manage to make it work.

Let's say we want to use a sequence in this Manipulate object, and use 1,2,3 as an input instead of {1,2,3}. How could we do it?

enter image description here

Posted 3 months ago

I suggest letting your input be a string. Then you can use Evaluate as follows:

input = "1, 2, 3";
Evaluate["{" <> input <> "}"]

This returns the list:

{1, 2, 3}
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract