MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: loop for with plot

  • To: mathgroup at
  • Subject: [mg110063] Re: loop for with plot
  • From: Bill Rowe <readnews at>
  • Date: Tue, 1 Jun 2010 04:19:27 -0400 (EDT)

On 5/30/10 at 6:47 AM, mariagiovannadainotti at (maria giovanna
dainotti) wrote:

>when I am using the loop for with plot is not working.

here is the example
For[e3=0,e3<4,e3++,Plot[{2*R3*Sin[ArcCos[x/R3]]*e3}, {x, -2R3,2 R3}]]
How can I sort out the problem?

A couple of things. First, there is no reason to surround the
expression you are plotting with curly braces "{", "}". While
this will not prevent Plot from working as desired, it is
unneeded since you only have a single expression to plot.

The key issue is the way For works. It doesn't return anything.
Consequently, enven though the plots are made, they don't show.
You can see this is the case by doing the following:

plotList = {};
For[e3 = 0, e3 < 4, e3++,
  plotList = {plotList,
    Plot[2*R3*Sin[ArcCos[x/R3]]*e3, {x, -2 R3, 2 R3}]}]

But I think a better approach would be to dispense with the For
loop altogether and use Table as follows:

Table[Plot[2*R3*Sin[ArcCos[x/R3]]*e3, {x, -2 R3, 2 R3}], {e3, 0, 3}]

  • Prev by Date: Displaying a table
  • Next by Date: Graphics3D question
  • Previous by thread: Re: Displaying a table
  • Next by thread: Graphics3D question