> # mapiter.ms # Graphical iteration of 1-d maps # > mapiter := proc(F, x0, a, b, skipiter, plotiter, caption) > local xp, k, p, orbit, curve, diag; > > xp := x0; # starting value > > # Skip the first few iterations if long term behaviour is desired. > # To plot all iterations use 0 for skipiter. > > p := array(0..plotiter); > for k from 1 to skipiter do xp := F(xp); od: > for k from 0 to plotiter do p[k] := xp; xp := F(xp); od; > > curve := plot(F(x), x=a..b, color=blue); > diag := plot(x, x=a..b, color=RGB(0,0,0)); > orbit := plot([seq(op([[p[k-1],p[k]],[p[k],p[k]]]), > k=1..plotiter)], > color=red); > plots[display]([orbit, curve, > diag],title=caption,scaling=CONSTRAINED); > end: # Test the procedure on the logistic map > Q := (x) -> a*x*(1-x); Q := x -> a x (1 - x) > # a := 2.9: mapiter(Q, 0.1, 0, 1, 0, 100,`a=2.9`); # period 1 > # a := 3.2: mapiter(Q, 0.1, 0, 1, 0, 100,`a=3.2`); # period 2 > # a := 3.5: mapiter(Q, 0.1, 0, 1, 1000, 100,`a=3.5`); # period 4 > # a := 3.56: mapiter(Q, 0.1, 0, 1, 1000, 100,`a=3.56`); # period 8 > # a := 3.74: mapiter(Q, 0.1, 0, 1, 1000, 100,`a=3.74`); # period 5 > #interface(plotdevice=postscript,plotoutput=`mapiter1.ps`); > a := 3.84: mapiter(Q, 0.1, 0, 1, 1000, 100,`a=3.84`); # period 3 > #interface(plotdevice=postscript,plotoutput=`mapiter2.ps`); > a := 3.9: mapiter(Q, 0.1, 0, 1, 1000, 100,`a=3.9`); # chaos # Try some other maps > # mapiter(cos, 0.1, 0, 1, 0, 100,`cos(x)`); > # mapiter((x) -> exp(-x), 0.1, 0, 1, 0, 100,`exp(-x)`); > # mapiter((x) -> arctan(x), 0.5, -1, 1, 0, 100,`arctan(x)`);