From: Guido Tripaldi on 30 May 2010 23:47 Hi Maria, 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
From: Bob Hanlon on 30 May 2010 23:48 >From 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 <mariagiovannadainotti(a)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}]] How can I sort out the problem? Best regards Maria
From: DC on 30 May 2010 23:48 One way to do it : 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 On 05/30/2010 11: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 > >
From: maria giovanna dainotti on 1 Jun 2010 04:22 Dear Bob, Chris, Murray, Helen, David, Christopher, thanks a lot for your precious help. I decided to use manipulate since I have many plots to do and I have now in troduced another variable in my function but in the plot doesn't appear anything. I will be very grateful if you could help me. Thanks a lot Cheers Maria 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 <hanlonr(a)cox.net> A: maria giovanna dainotti <mariagiovannadainotti(a)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 <mariagiovannadainotti(a)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 <hanlonr(a)cox.net> A: maria giovanna dainotti <mariagiovannadainotti(a)yahoo.it>; mathgroup(a)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 <mariagiovannadainotti(a)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}]] How can I sort out the problem? Best regards Maria
From: Bill Rowe on 1 Jun 2010 04:19 On 5/30/10 at 6:47 AM, mariagiovannadainotti(a)yahoo.it (maria giovanna dainotti) wrote: >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}]
First
|
Prev
|
Pages: 1 2 Prev: Mathematica help (plotting solutions of transendental Next: Basic normal and t table questions |