%Illustrates intermittancy via bottleneck in graphical iteration
%Calls for the input of a polynomial P and an initial seed x

close all
P=input('input polynomial P ');
p=input('initial value =');
w=linspace(0,1,400);
z=polyval(P,w);
plot(w,w)
hold on
plot(w,z)
x=zeros(50,1);
y=zeros(50,1);
x(1)=p;
y(1)=polyval(P,x(1));
for k=1:50
	y(k)=polyval(P,x(k));
if (abs(y(k)-x(k))<.07)
	plot([x(k) x(k)],[x(k),y(k)],'k')
	plot([x(k),y(k)],[y(k),y(k)],'k')
	 else
	plot([x(k) x(k)],[x(k),y(k)],'g')
	plot([x(k),y(k)],[y(k),y(k)],'g' )
	end
	x(k+1)=y(k);
	k=k+1;
end	
