Message Boards Message Boards

0
|
16805 Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:
GROUPS:

PLOT in loop !

Posted 11 years ago

why "DO" loop does not work with "PLOT" function? (i'm using mathematica 9)

Attachments:
POSTED BY: covert opps
4 Replies
Posted 11 years ago

Like this:

Table[Plot[x^n, {x, -5, 5}], {n, 1, 10}]
POSTED BY: Priyan Fernando

David's suggestion is precise. You can also improve from David's suggestion by using Table instead of appending list. The reason is that every time you append something to a list, the kernel dynamically increase the size of the list, which is pretty slow if you have more items being created.

POSTED BY: Shenghui Yang

Do evaluates its arguments but does not return a value.

Although Print is a convenient hack to get a graphic (or something else) output from a Do loop, it is strongly discouraged. Print's main use is as a tool to employ in debugging. If you want to see the graphics that you generate from within a Do loop you should do something like assign each of them to a parameter or place them in a list that is assigned to a parameter and then execute that parameter to return the graphics in an Output cell. Or you could create a formatted expression with those graphics in, for example, a GraphicsGrid or a Grid or a Column.

Here is an example:

plots = {};
Do[AppendTo[plots, Plot[x^n, {x, -10, 10}]], {n, 1, 5}];
Column[plots]
POSTED BY: David Reiss
Posted 11 years ago

You need to wrap a Print around the Plot

Do[Print[Plot[x^n, {x, -5, 5}]], {n, 1, 10}]
POSTED BY: Priyan Fernando
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