Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: newbie: programmatic sequence of plots?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg96817] Re: newbie: programmatic sequence of plots?
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Wed, 25 Feb 2009 04:07:03 -0500 (EST)
  • References: <go0j4b$n0o$1@smc.vnet.net>

Tom Roche wrote:
> How to get a programmatic sequence of plots?
> 
> As advertised by the Subject:, I'm new to Mathematica (specifically
> 7.0.0 for Students for 32-bit Windows on XP Pro) so please excuse any
> lapses in terminology. I'd also appreciate pointers to specific docs
> rather than just an RTFM.
> 
> Since I'm currently unable to model the logistic map y=a y (1-y) (see
> previous post) I'm trying to do a series of plots of it, to see how
> behavior changes over time. I can get a plot of a single instance with
> 
> Clear[a,y,y0,nRecurr];
> a=3.5;
> y0=0.4;
> nRecurr=50;
> ListPlot[
>   RecurrenceTable[{y[n+1]==a y[n] (1-y[n]),y[0]==y0},
>     y,{n,1,nRecurr}],Joined->True
> ]
> 
> I can get a sequence of tables of values with
> 
> Clear[a, y, y0, nRecurr, yinit, yinc, yfinal];
> a = 3.5;
> nRecurr = 50;
> yinit = 0.1;
> yinc = 0.01;
> yfinal = 0.2;
> For[y0 = yinit, y0 <= yfinal, y0 += yinc, Print[y0, ":\n",
>   RecurrenceTable[{y[n + 1] == a y[n] (1 - y[n]), y[0] == y0}, y, {n,
> 1, nRecurr}]]]
> 
> But when I try to plot those values with
> 
> Clear[a, y, y0, nRecurr, yinit, yinc, yfinal];
> a = 3.5;
> nRecurr = 50;
> yinit = 0.1;
> yinc = 0.01;
> yfinal = 0.2;
> For[y0 = yinit, y0 <= yfinal, y0 += yinc,
>   ListPlot[
>     RecurrenceTable[
>       {y[n + 1] == a y[n] (1 - y[n]), y[0] == y0}, y, {n, 1, nRecurr}
>     ]
>     ,Joined->True]
> ]
> 
> I get absolutely nothing: no plot, no error message, no nada.
> Similarly, when I try to plot the difference between two runs of the
> map with
> 
> seqDiff[a_,y_,inc_]:=Module[
>   {r=y,s=y+inc},
>   ListPlot[
>     Table[r=a r (1-r),{50}]-Table[s=a s (1-s),{50}],
>     Joined->True,PlotRange->{-1,1}
>   ]
> ]
> seqDiff[4.0,0.3,0.1]
> 
> I get a plot. But when I try to put that inside a for loop
> 
> Clear[a, i,init,inc,final];
> a = 4.0;
> init=0.3;
> inc=0.1;
> final=0.5;
> For[i=init,i<=final,i+=inc,seqDiff[a,i,inc]]
> 
> I get nothing: no plot, no error message.
> 
> What am I doing wrong? How to get a series of plots?

Just do what you did with the tables: Print the plots. You should
understand that plots are no different than any other expression in
Mathematica and only when returned as output, Mathematica knows how to
format them. Since your For loop never returns anything, nothing is
shown, just as you would expect for other expressions, too. Note that
this has changed from version 5.2 to version 6.

Another hint: Using Do instead of For leads to code which is easier to
understand and less error prone. It also has the advantage that the
syntax is exactly like that of Table which would 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.

hth,

albert


  • Prev by Date: Re: Re: Interval arithmetic and Dependency problems
  • Next by Date: Re: newbie: programmatic sequence of plots?
  • Previous by thread: newbie: programmatic sequence of plots?
  • Next by thread: Re: newbie: programmatic sequence of plots?