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
R3 = 6;
functions = Table[2*R3*Sin[ArcCos[x/R3]]*e3, {e3, 0, 3}]
Plot[functions, {x, -2 R3, 2 R3}]
David Park
djm...@comcast.net
http://home.comcast.net/~djmpark/
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
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 mur...@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
either use
For[e3=0,e3<4,e3++,Print@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 <mariagiova...@yahoo.it>:
the "For" loop in Mathematica is actually an 'expression', not an 'instruction'. This means that the output doesn't depend directly from what is done within the loop, but it depends from what the expression explicitly return, and the default value returned by For is Null. To display every iteration result you have to "Print" it out:
R1 == 1.029;
R2 == 3;
R3 == 6;
e1 == 27;
e2 == 0;
e3 == 2.5;
For[e3 == 0, e3 < 4, e3++,
Print[Plot[{2*R3*Sin[ArcCos[x/R3]]*e3}, {x, -2 R3, 2 R3}]]]
As you can see if you put the Plot[] inside a Print[], everything will work as you expected.
if you doesn't want to use the Print[], you can append each 'For' iteration result in a list, and use the content of the list (namely your plots) after the For expression:
R1 == 1.029;
R2 == 3;
R3 == 6;
e1 == 27;
e2 == 0;
e3 == 2.5;
myPlots == {}; (* we need an empty initialized list to Append items in it *)
For[e3 == 0, e3 < 4, e3++,
AppendTo[ myPlots,
Plot[{2*R3*Sin[ArcCos[x/R3]]*e3}, {x, -2 R3, 2 R3}]]]
myPlots (* display results *)
Perhaps better of all is to use the 'Table' instead of 'For', in output you will obtain the same 'list of plots' of above, but it is more "Mathematica Style:
R1 == 1.029;
R2 == 3;
R3 == 6;
e1 == 27;
e2 == 0;
e3 == 2.5;
myPlots == Table[Plot[{2*R3*Sin[ArcCos[x/R3]]*e3}, {x, -2 R3, 2 R3}], {e3, 0, 3}];
Grid[{myPlots}, Frame -> True] (* display results in a frame *)
cheers,
G
Il giorno 30/mag/2010, alle ore 12.47, maria giovanna dainotti ha scritto:
> 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
>
>
---
Guido Tripaldi
R3 = 6;
For[e3 = 0, e3 < 4, e3++,
Print[Plot[
2*R3*Sin[ArcCos[x/R3]]*e3,
{x, -2 R3, 2 R3},
PlotRange -> {0, 36}]]]
However, Table is generally more useful
Plot[
Evaluate[
Table[
Tooltip[
2*R3*Sin[ArcCos[x/R3]]*e3, e3],
{e3, 0, 3}]],
{x, -2 R3, 2 R3}]
Plot[
Evaluate[
Tooltip[
Table[
2*R3*Sin[ArcCos[x/R3]]*e3,
{e3, 0, 3}]]],
{x, -2 R3, 2 R3}]
Bob Hanlon
---- maria giovanna dainotti <mariagiova...@yahoo.it> 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}]]
R1 = 1.029
R2 = 3
R3 = 6
e1 = 27
e2 = 0
e3 = 2.5
Map[Plot[{2*R3*Sin[ArcCos[x/R3]]*#}, {x, -2 R3, 2 R3}] &,
Range[0, 3, 1]]
-Francesco
R1==1.029
R2==3
R3==6
e1==27
e2==0
e3==2.5
i==15
Manipulate[Plot[Tooltip[{2*R3/cos[i]*Sin[ArcCos[Re[x*cos[i]/R3]]]*e3+2*R2/cos[i]*Sin[ArcCos[Re[x*cos[i]/R2]]]*(e2-e3)+2*R1/cos[i]*Sin[ArcCos[Re[x*cos[i]/R1]]]*(e1-e2),(2*R3/cos[i]*Sin[ArcCos[Re[x*cos[i]/R3]]]*e3+2*R2/cos[i]*Sin[ArcCos[Re[x*cos[i]/R2]]]*(e2-e3))*(Boole[-R2=A3x<-R1]+Boole[R2>x>R1]),2*R3/cos[i]*Sin[ArcCos[Re[x*cos[i]/R3]]]*e3*(Boole[x<-R2]+Boole[x>R2])}],{x,-2 R2,2 R2},PlotRange=AEFull],{R2,2,4,1,Appearance=AE"Labeled"},{e2,0,2,.1,Appearance=AE"Labeled"},{e3,1,3,.5,Appearance=AE"Labeled"},{i,0,60,1,Appearance=AE"Labeled"}]
________________________________
Da: Bob Hanlon <han...@cox.net>
A: maria giovanna dainotti <mariagiova...@yahoo.it>
Inviato: Dom 30 maggio 2010, 17:45:54
Oggetto: Re: loop for with plot
R1 == 1.029;
R2 == 3;
R3 == 6;
e1 == 200;
e2 == 0;
e3 == 2.5;
Your inequalities were garbled. Correct my fixes if they are not what you intended. In addition, presumably you want the logical Or ( || ) of the Boole statements rather than their Sum ( + ).
Plot[{
2*R3*Sin[ArcCos[x/R3]]*e3 +
2*R2*Sin[ArcCos[x/R2]]*(e2 - e3) +
2*R1*Sin[ArcCos[x/R1]]*(e1 - e2),
(2*R3*Sin[ArcCos[x/R3]]*e3 +
2*R2*Sin[ArcCos[x/R2]]*(e2 - e3))*
(Boole[-R2 <== x < -R1] || Boole[R2 > x > R1]),
2*R3*Sin[ArcCos[x/R3]]*e3*
(Boole[x < -R2] || Boole[x > R2])},
{x, -2 R2, 2 R2}, PlotRange -> Full]
In your definition of functions you used square brackets where you needed List brackets.
In the Table you can step the variables in any increment that you want
functions == Flatten[
Table[{
2*R3*Sin[ArcCos[x/R3]]*e3 +
2*R2*Sin[ArcCos[x/R2]]*(e2 - e3) +
2*R1*Sin[ArcCos[x/R1]]*(e1 - e2),
(2*R3*Sin[ArcCos[x/R3]]*e3 +
2*R2*Sin[ArcCos[x/R2]]*(e2 - e3))*
(Boole[-R2 <== x < -R1] || Boole[R2 > x > R1]),
2*R3*Sin[ArcCos[x/R3]]*e3*
(Boole[x < -R2] || Boole[x > R2])},
{R2, 2, 4}, {e2, 0.1, 2, 0.1}, {e3, 1, 3}]];
However,
Length[functions]
540
That is a lot of graphs on a single Plot. Why not use Manipulate for some or all of the variables.
Again, you can step in any increments that you want.
Manipulate[
Plot[Tooltip[
{2*R3*Sin[ArcCos[x/R3]]*e3 +
2*R2*Sin[ArcCos[x/R2]]*(e2 - e3) +
2*R1*Sin[ArcCos[x/R1]]*(e1 - e2),
(2*R3*Sin[ArcCos[x/R3]]*e3 +
2*R2*Sin[ArcCos[x/R2]]*(e2 - e3))*
(Boole[-R2 <== x < -R1] || Boole[R2 > x > R1]),
2*R3*Sin[ArcCos[x/R3]]*e3*
(Boole[x < -R2] || Boole[x > R2])}],
{x, -2 R2, 2 R2},
PlotRange -> {0, 450}],
{R2, 2, 4, 1, Appearance -> "Labeled"},
{e2, .1, 2, .1, Appearance -> "Labeled"},
{e3, 1, 3, .5, Appearance -> "Labeled"}]
Bob Hanlon
---- maria giovanna dainotti <mariagiova...@yahoo.it> wrote:
==========================
thanks for your help. It works on that function but when i add all the functions together says that the syntax is not well defined.
I report here the example
R1==1.029
R2==3
R3==6
e1=0
e2==0
e3==2.5
Plot[{2*R3*Sin[ArcCos[x/R3]]*e3+2*R2*Sin[ArcCos[x/R2]]*(e2-e3)+2*R1*Sin[ArcCos[x/R1]]*(e1-e2),(2*R3*Sin[ArcCos[x/R3]]*e3+2*R2*Sin[ArcCos[x/R2]]*(e2-e3))*(Boole[-R2<==x=A3-R1]+Boole[R2>x>R1]),=A3-R2]+Boole[x>R2])}, {x, -2R2,2R2},PlotRange=AEFull]
2*R3*Sin[ArcCos[x/R3]]*e3*(Boole[x
So when I do
functions==Table[[2*R3*Sin[ArcCos[x/R3]]*e3+2*R2*Sin[ArcCos[x/R2]]*(e2-e3)+2*R1*Sin[ArcCos[x/R1]]*(e1-e2),(2*R3*Sin[ArcCos[x/R3]]*e3+2*R2*Sin[ArcCos[x/R2]]*(e2-e3))*(Boole[-R2<==x
2*R3*Sin[ArcCos[x/R3]]*e3*(Boole[x
I would like that they go from 0.1 in 0.1 and not only from integer values.
Thanks a lot for your help
Cheers
Maria
=A3-R1]+Boole[R2>x>R1]),=A3-R2]+Boole[x>R2])],{R2,2,4},{e2,0.1,2},{e3,1,3}]
________________________________
Da: Bob Hanlon <han...@cox.net>
A: maria giovanna dainotti <mariagiova...@yahoo.it>; math...@smc.vnet.net
Inviato: Dom 30 maggio 2010, 16:14:49
Oggetto: Re: loop for with plot
=46rom the documentation: "Unless an explicit Return is used, the value returned by For is Null." You must explicitly display (Print) the plots.
R3 == 6;
For[e3 == 0, e3 < 4, e3++,
Print[Plot[
2*R3*Sin[ArcCos[x/R3]]*e3,
{x, -2 R3, 2 R3},
PlotRange -> {0, 36}]]]
However, Table is generally more useful
Plot[
Evaluate[
Table[
Tooltip[
2*R3*Sin[ArcCos[x/R3]]*e3, e3],
{e3, 0, 3}]],
{x, -2 R3, 2 R3}]
Plot[
Evaluate[
Tooltip[
Table[
2*R3*Sin[ArcCos[x/R3]]*e3,
{e3, 0, 3}]]],
{x, -2 R3, 2 R3}]
Bob Hanlon
---- maria giovanna dainotti <mariagiova...@yahoo.it> 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}]]
>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?
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}]}]
Flatten[plotList]
But I think a better approach would be to dispense with the For
loop altogether and use Table as follows:
Clear[e3];
Table[Plot[2*R3*Sin[ArcCos[x/R3]]*e3, {x, -2 R3, 2 R3}], {e3, 0, 3}]