(*Adapted by Rafael Luís: rafaelluis@netmadeira.com
 2016-09-11: adapted for Mathematica v.10 by Ross Moore *)

(*Cobweb for cubic Map*)

(*Function and parameters*)

(*Asymptotic stability Right*)

Clear[f,r,x,x0,iterates];
f[x_,r_]:=r×x-x^3; (*Function*)
x0=0.6;     (*initial values*)
r=1;      (*parameter*)
iterates=20;

LogisticSegments[r_,x0_,its_]:=Module[
{l=NestList[r× #-#^3&,x0,its]},
Partition[Flatten[Transpose[{l,l}]],2,1]
]

p2=Partition[LogisticSegments[r,x0,iterates],2,1];

Manipulate[Plot[{f[x,r],x},{x,-1,1},PlotRange->{-0.5,0.5},PlotStyle->{{},Dashing[{.02}]},
Prolog->MapIndexed[{Hue[Length[#]/Length[p2]],Line[#]}&,Take[p2,2i]],
AspectRatio->Automatic,
AxesLabel->TraditionalForm/@{(Subscript[x, n]),(Subscript[x, n+1])}
],{{i,10,"iterates"},Range[Length[p2]/2]}]

(*Asymptotic stability Left*)

Clear[f,r,x,x0,iterates];
f[x_,r_]:=r×x-x^3; (*Function*)
x0=-0.6;     (*initial values*)
r=1;      (*parameter*)
iterates=20;

LogisticSegments[r_,x0_,its_]:=Module[
{l=NestList[r× #-#^3&,x0,its]},
Partition[Flatten[Transpose[{l,l}]],2,1]
]

p2=Partition[LogisticSegments[r,x0,iterates],2,1];

Manipulate[Plot[{f[x,r],x},{x,-1,1},PlotRange->{-0.5,0.5},PlotStyle->{{},Dashing[{.02}]},
Prolog->MapIndexed[{Hue[Length[#]/Length[p2]],Line[#]}&,Take[p2,2i]],
AspectRatio->Automatic,
AxesLabel->TraditionalForm/@{(Subscript[x, n]),(Subscript[x, n+1])}
],{{i,10,"iterates"},Range[Length[p2]/2]}]