% % Code to perform simple iteration and show cobweb plot for a mapping % % x_{n+1} = f(x_n) n=0,1,2,... % clear clf a=input(' Enter parameter a: '); % constant for logistic map xstart=input(' Enter the left-hand plot limit: '); xend=input(' Enter the right-hand plot limit: '); x=xstart:0.001:xend; plot(x,func(x,a),'r',x,x,'r') axis([xstart xend xstart xend]) % scale picture axis('square'); % ensure plot is square hold on x(1)=input(' Enter x_0: '); nmax=input(' Enter the number of iterations: '); format long fprintf('\n n iterate \n') % Print table header for n=1:nmax x(n+1)=func(x(n),a); fprintf(' %3.0f %10.6f \n', n,x(n+1)) %Print iterate if (n>1) plot( [x(n) x(n)], [x(n) x(n+1)],'b'); end %vertical line plot( [x(n) x(n+1)], [x(n+1) x(n+1)],'b--') %horizontal line pause end