function basinHenon(num) %finds the basin of attraction for the Henon attractor xmin=-8.0; xmax=8.0; ymin=-11.0; ymax=5.0; escape = 20.0; tmax = 20; dx=(xmax-xmin)/(num-1); dy=(ymax-ymin)/(num-1); Boxes=zeros(num); for i=1:num, for j=1:num, x=xmin+(i-1)*dx; y=ymax -(j-1)*dy; for t=1:tmax, [x,y]=henon(x,y); if abs(y) > escape break; end end if(t ~= tmax) %leave 0 for trapped set Boxes(j,i)=t; % For image the order is y,x, with (1,1) at top left end end end xvect = linspace(xmin,xmax,num); yvect = linspace(ymax,ymin,num); bmax = max(max(Boxes)) Boxes = (Boxes)*100/bmax; % scale to range 100 elements in default color map image(xvect,yvect, Boxes); % plot the matrix as an image & scale to colormap colormap(hot); map = colormap; mapnew = flipud(map); mapnew(1,1)=0; mapnew(1,2)=0; mapnew(1,3)=0; colormap(mapnew); colorbar; axis xy % reverse the y axis to normal hold on iterate(1,1,1000) %plot the attractor too hold off