% % logweb.m - this MATLAB file solves the % discrete logistic equation x(i+1)=r*x(i)*(1-x(i)) % and illustrates cobwebbing analysis for two % points chosen by the user to illustrate the % stretching and folding of a non-linear map % The user is prompted to read in the value % of r to use as well as two initial values % x0 and z1 which must be in (0,1) % and the time interval over which to run the % simulation. !c: s=1; while s>0; r=input('input growth rate r: ') x0=input('input initial population x0: ') z0=input('input second initial population z0: ') n=input('end of time interval b: ') x=zeros(n+1,1); z=zeros(n+1,1); t=zeros(n+1,1); x(1)=x0; z(1)=z0; tt(1)=0; for i=1:n t(i)=i-1; x(i+1)=r*x(i)*(1-x(i)); z(i+1)=r*z(i)*(1-z(i)); end t(n+1)=n; nn=100; del=1./nn; xstart=0; yy=zeros(nn+1,1); lin=zeros(nn+1,1); xx=zeros(nn+1,1); for i=1:nn+1 xx(i)=xstart+(i-1)*del; lin(i)=xx(i); yy(i)=r*xx(i)*(1-xx(i)); end plot(xx,lin,xx,yy),pause xc=zeros(24,1); yc=zeros(24,1); xc(1)=x0; yc(1)=0; xc(2)=x0; yc(2)=r*x0*(1-x0); yc(3)=yc(2); xc(3)=yc(2); zc=zeros(24,1); zyc=zeros(24,1); zc(1)=z0; zyc(1)=0; zc(2)=z0; zyc(2)=r*z0*(1-z0); zyc(3)=zyc(2); zc(3)=zyc(2); plot(xx,lin,xx,yy,xc,yc,zc,zyc),pause for j=4:12; jj=2*j-4; xc(jj)=xc(jj-1); yc(jj)=r*xc(jj)*(1-xc(jj)); xc(jj+1)=yc(jj); yc(jj+1)=yc(jj); zc(jj)=zc(jj-1); zyc(jj)=r*zc(jj)*(1-zc(jj)); zc(jj+1)=zyc(jj); zyc(jj+1)=zyc(jj); plot(xx,lin,xx,yy,xc,yc,zc,zyc),pause end plot(t,x,t,x,'o',t,z,t,z,'+'),pause s=input('Do you want to stop - if so enter 0') end