% bakercolor(n,c) uses color to display the first 8 iterations of the baker's map on n points with starting locations c. % Enter bakercolor(1000,1) at the Matlab command prompt to run it. function [void] = bakercolor(n,c) switch c case 1, x = rand(1000,1); y = rand(1000,1); case 2, x = 0.25 + 0.25*rand(1000,1); y = 0.5*rand(1000,1); case 3, x = rand(1000,1); y = x + 0.25*rand(1000,1); case 4, [x,y] = meshgrid(0:0.04:1, 0:0.04:1); x = 0.5*reshape(x,prod(size(x)),1); y = 0.5*reshape(y,prod(size(x)),1); case 5, [x,y] = meshgrid(0:0.05:1, 0:0.05:1); x = reshape(x,prod(size(x)),1); y = reshape(y,prod(size(x)),1); case 6, [x,y] = meshgrid(0:0.04:1, 0:0.04:1); x = reshape(x,prod(size(x)),1); y = reshape(y,prod(size(x)),1); case 7, [x,y] = meshgrid(0:0.1:3, 0:0.1:3); x = reshape(x,prod(size(x)),1)/3; y = reshape(y,prod(size(x)),1)/3; case 8, [x,y] = meshgrid(0:0.2:7, 0:0.2:7); x = reshape(x,prod(size(x)),1)/7; y = reshape(y,prod(size(x)),1)/7; case 9, [x,y] = meshgrid(0:0.2:7, 0:0.2:7); x = reshape(x,prod(size(x)),1)/7; y = rand(length(x),1); end k=find(x>0.5); j=find(x<=0.5); clf for i=1:8, subplot(4,2,2*mod(i-1,4)+1+fix((i-1)/4)) % plot(x(k), y(k), 'g.', 'markersize', 12); % good for gray-scale printing plot(x(k), y(k), 'r.', 'markersize', 12); hold on % plot(x(j), y(j), 'k.', 'markersize', 12); % good for gray-scale printing plot(x(j), y(j), 'b.', 'markersize', 12); axis([0 1 0 1]); title(['Iteration ' int2str(i-1)]); X = mod(2*x,1); Y = (y + (x > 0.5))/2; x = X; y = Y; end xlabel('Blue points may cover up red points')