clear; close all % % Problem 30 p. 216 % % Sierpinski triangles % x = 0; y = 0; n = 30000; r = randi(3,n,1); f = sqrt(3)/4; for i=1:n-1 switch r(i) case 1 x(i+1) = 0.5*x(i); y(i+1) = 0.5*y(i); case 2 x(i+1) = 0.5*x(i) + 0.25; y(i+1) = 0.5*y(i) + f; case 3 x(i+1) = 0.5*x(i)+ 0.5; y(i+1) = 0.5*y(i); end end plot(x,y,'^') axis off