Re: newbie: programmatic sequence of plots?

*To*: mathgroup at smc.vnet.net*Subject*: [mg96962] Re: newbie: programmatic sequence of plots?*From*: Albert Retey <awnl at gmx-topmail.de>*Date*: Sat, 28 Feb 2009 06:42:31 -0500 (EST)*References*: <go0j4b$n0o$1@smc.vnet.net> <go31og$fga$1@smc.vnet.net> <go8hs9$kvm$1@smc.vnet.net>

Tom Roche wrote: > Sjoerd C. de Vries Wed, 25 Feb 2009 09:05:27 +0000 (UTC) >> Loops themselves only have a null return value. > > Doh! I was assuming ListPlot would have a "side effect." > > Albert Retey Wed, 25 Feb 2009 09:06:32 +0000 (UTC) >> return a list of these plots additionaly or instead of just >> printing them, so that you can use ListAnimation or TabView or >> whatever you like for displaying them. > > And the way to do that is > > "m.g." Wed, 25 Feb 2009 09:07:28 +0000 (UTC) >> Clear[a, y, y0, nRecurr, yinit, yinc, yfinal]; >> a = 3.5; >> nRecurr = 50; >> yinit = 0.1; >> yinc = 0.01; >> yfinal = 0.2; >> out = {}; (* modification here *) >> For[y0 = yinit, y0 <= yfinal, y0 += yinc, >> AppendTo[out, (* modification here *) >> ListPlot[ >> RecurrenceTable[{y[n + 1] == a y[n] (1 - y[n]), y[0] == y0}, >> y, {n, 1, nRecurr}]]]; >> ]; >> out (* modification here *) > > So I modified that to do > > For[y0 = yinit, y0 <= yfinal, y0 += yinc, > AppendTo[out, > ListPlot[ > RecurrenceTable[{y[n + 1] == a y[n] (1 - y[n]), y[0] == y0}, > y, {n, 1, nRecurr}], Joined -> True > ] > ]; > ]; > ListAnimate[out] > > which is even better than printing a list of static plots. just another suggestion for improvement: In Mathematica loops are often only the second best solution, and using AppendTo within a loop is rather inefficient (probably not a problem in this example). I think this is close to what you would use after using Mathematica for a while: plotlst = Table[ ListPlot[ RecurrenceTable[{y[n + 1] == a y[n] (1 - y[n]), y[0] == y0}, y, {n, 1, nRecurr}], Joined -> True ], {y0, yinit, yfinal, yinc} ]; ListAnimate[plotlst] (I haven't tested the code, but think it should work) hth, albert