Group Abstract Group Abstract

Message Boards Message Boards

0
|
12K Views
|
8 Replies
|
1 Total Like
View groups...
Share
Share this post:

Wierd output when working with Module function

Posted 6 years ago

Hello everyone

Why does the outputs of these:

t=1;
x0 = Table[i, {i, 1, 100}];
y0 = Table[Sin[(20 + i)/20 t], {i, 0, 99}];
data = N[Table[{x0[[i]], y0[[i]]}, {i, 1, 100}]]
  ListPlot[data]

and this:

Module[
{t = 1},
 x0 = Table[i, {i, 1, 100}];
 y0 = Table[Sin[(20 + i)/20 t], {i, 0, 99}];
 data = N[Table[{x0[[i]], y0[[i]]}, {i, 1, 100}]]
   ListPlot[data]
 ]

are different?

The latter output is weird, it is a list of ListPlots, and that is not what I am looking for.

POSTED BY: Ehud Behar
8 Replies
POSTED BY: W. Craig Carter
POSTED BY: Szabolcs Horvát

Because you forgot a ; at the end of the data = ... line. The newline (i.e. whitespace) after that line will be interpreted as multiplication. The system actually warns you: it displays a $\times$ sign.

POSTED BY: Szabolcs Horvát
Posted 6 years ago

Thanks! That's right. Actually there is no grey multiplication sign on my notebook, and that was my source for confusion.

Another question then arises:

Is there any way to use Module and still show the output of two different commands, as I tried to do on the original post?

POSTED BY: Ehud Behar
Posted 6 years ago

You could change the last expression in the Module to

{data, ListPlot[data]}
POSTED BY: Rohit Namjoshi
Posted 6 years ago

Thanks, but I rather want them to be returned on two separate output lines, if that's possible.

POSTED BY: Ehud Behar
Posted 6 years ago
POSTED BY: Mike Besso
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard