Message Boards Message Boards

0
|
2392 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

DO loop into a list

Posted 11 years ago

Hello,

i have a structure, which is of a form

Do[Module[{parameters initiation.....}, 
x=some function with respect to g]; 
 Print[x], {g, {1, 2,3,4,5}}]

The above gives sequentially the solution in scalar values.

Instead, i would like to have the result (incrementally) in a list. How can this happen?

Thank you in advance

POSTED BY: nikos miridakis
2 Replies

Let's say that your function is f[g] then

Map[f, Range[5]]

would give you want you want in your particular case

 {f[1], f[2], f[3], f[4], f[5]}
POSTED BY: David Reiss

You might want to look at the functions Sow/Reap or alternatively AppendTo.

Cheers, M.

POSTED BY: Marco Thiel
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