Message Boards Message Boards

0
|
4083 Views
|
5 Replies
|
3 Total Likes
View groups...
Share
Share this post:

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

Posted 4 years ago

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?

POSTED BY: Francesco Lasco
5 Replies
Posted 4 years 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}
POSTED BY: Mike Besso

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 BY: Francesco Lasco

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 BY: Francesco Lasco
Posted 4 years 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 BY: Mike Besso
Posted 4 years 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 BY: Rohit Namjoshi
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