%Example script file to construct the Serpinski Gasket. x=rand(2,1); A=[0.5,0;0,0.5]; b1=[0;0]; b2=[0;0.5]; b3=[0.5;0]; numits=50000; y=zeros(2,numits); %We'll be throwing away the first few points... for i=1:100 k=ceil(3*rand); if k==1 z=A*x+b1; elseif k==2 z=A*x+b2; else z=A*x+b3; end x=z; end %Keep these for plotting for i=1:numits k=ceil(3*rand); if k==1 y(:,i)=A*x+b1; elseif k==2 y(:,i)=A*x+b2; else y(:,i)=A*x+b3; end x=y(:,i); end %Now use the command: %plot(y(1,:),y(2,:),'k.','Markersize',3); %The Markersize command reduces the size of each %point. If you leave it off, the dots are kind of big.