Re: loop for with plot
- To: mathgroup at smc.vnet.net
- Subject: [mg110063] Re: loop for with plot
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Tue, 1 Jun 2010 04:19:27 -0400 (EDT)
On 5/30/10 at 6:47 AM, mariagiovannadainotti at 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}]