From: maria giovanna dainotti on
Dear Mathgroup,

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

here is the example
R1=1.029
R2=3
R3=6
e1=27
e2=0
e3=2.5
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?
Best regards
Maria


From: David Park on
You can use the much simpler Table instead of For. It is usually good to
evaluate the functions you are plotting before putting them into a Plot
statement. So:

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


David Park
djmpark(a)comcast.net
http://home.comcast.net/~djmpark/


From: maria giovanna dainotti [mailto:mariagiovannadainotti(a)yahoo.it]

Dear Mathgroup,

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

here is the example
R1=1.029
R2=3
R3=6
e1=27
e2=0
e3=2.5
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?
Best regards
Maria




From: Helen Read on
On 5/30/2010 6:47 AM, maria giovanna dainotti wrote:
> Dear Mathgroup,
>
> when I am using the loop for with plot is not working.
>
> here is the example
> R1=1.029
> R2=3
> R3=6
> e1=27
> e2=0
> e3=2.5
> 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?
> Best regards
> Maria

For (and similarly Do) by default returns Null as output. If you want to
see the plot at each iteration in the loop, you need to explicitly print
it, like this.

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

That said, it would be much easier to simply make a table. Also, it is
good practice to begin names of variables and functions with lower case
letters, to avoid inadvertent conflicts with built-in functions and
symbols. And lastly, if you intend to vary your parameters, it is worth
learning to define functions in Mathematica, so that your variables are
actually variables, instead of redefining constants each time you want
to make a change.

I would do something like the following. (I've renamed your R3 and e3 as
a and b respectively.)

f[x_, a_, b_] := 2 a b Sin[ArcCos[x/a]]

Now make a table of plots, for b from 1 to 4, with a=6.

Table[Plot[f[x, 6, b], {x, -10, 10}], {b, 1, 4}]

Or make a plot of a table of functions, if you'd like them all together.

Plot[Table[f[x, 6, b], {b, 1, 4}], {x, -10, 10}]

Now try varying a. I'll label each plot with the value of a.

Table[Plot[Table[f[x, a, b], {b, 1, 4}], {x, -10, 10},
PlotLabel -> a], {a, 1,5}]


Table[Plot[Table[f[x, a, b], {b, 1, 4}], {x, -10, 10},
PlotLabel -> a], {a, 2, 10, 2}]



--
Helen Read
University of Vermont

From: Murray Eisenberg on
This is a commonly-asked question (although most folks who ask usually
have the same problem with Do rather than For). The key is what the
documentation says about For:

Unless an explicit Return is used, the value returned by For is Null.

To get the body of the For to produce output for each value of the
counter, just include a Print -- just like the very first Basic Example
in the docs show:

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

(pretty-printed for syntactical clarity).


On 5/30/2010 6:47 AM, maria giovanna dainotti wrote:
> Dear Mathgroup,
>
> when I am using the loop for with plot is not working.
>
> here is the example
> R1=1.029
> R2=3
> R3=6
> e1=27
> e2=0
> e3=2.5
> 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?
> Best regards
> Maria
>
>

--
Murray Eisenberg murray(a)math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2859 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305

From: Peter Pein on
Hi Maria,

either use
For[e3=0,e3<4,e3++,Print(a)Plot[2*R3*Sin[ArcCos[x/R3]]*e3,{x,-2R3,2 R3}]]
to get five plots displyed, or
Table[Plot[2*R3*Sin[ArcCos[x/R3]]*e3, {x, -2*R3, 2*R3}], {e3, 0, 4}]
to get a list of these plots, or to display them in one plot:
Plot[Evaluate[Table[2*R3*Sin[ArcCos[x/R3]]*e3, {e3, 0, 4}]], {x, -2*R3,
2*R3}]


Peter

Am Sun, 30 May 2010 10:47:44 +0000 (UTC)
schrieb maria giovanna dainotti <mariagiovannadainotti(a)yahoo.it>:

> Dear Mathgroup,
>
> when I am using the loop for with plot is not working.
>
> here is the example
> R1=1.029
> R2=3
> R3=6
> e1=27
> e2=0
> e3=2.5
> 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?
> Best regards
> Maria
>
>