function MSierp(N)
T{1} = [1/2 0 0; 0 1/2 0; 0 0 1] ;
T{2} = [1/2 0 1/2; 0 1/2 0; 0 0 1];
T{3} = [1/2 0 1/4; 0 1/2 0.433 ; 0 0 1];
X = zeros(3,N); % memory for the points
X(:,1) = [0.25; 0.25; 1]; % initial point (column 1, row x and row y)
for i = 1:N-1
r = rand; % random choice of the Rule (1,2 or 3)
if r<1/3
Rule = 1;
elseif r<2/3
Rule = 2;
elseif r<3/3
Rule = 3;
end
X(:,i+1) = T{Rule}*X(:,i);
end
figure(1);
% plots all points at the end
plot(X(1,:),X(2,:),'.','Color',[0 0 0 ],'MarkerSize',2);
axis off;
end