145k views
3 votes
The Sierpinski triangle can be implemented in MATLAB by plotting points iteratively according to one of the following three rules that are selected randomly with equal probability. Rule 1: x_n + 1 = 0.5x_n, y_n + 1 = 0.5y_n Rule2: x_n + 1 = 0.5x_n + 0.25, y_n + 1 = 0.5y_n+|( 3)/4 Rule 3: x_n + 1, = 0.5x_n + 0.5, y_n + 1 = 0.5y_n Write a program in a script file that calculates the x and y vectors and then plots y versus x as individual points (use plot (x, y, )). Start with x1 = 0 and y1 = 0. Run the program four times with 10, 100, 1,000, and 10,000 iterations.

1 Answer

3 votes

Answer:

See explaination and attachment for theprogram code and output.

Step-by-step explanation:

matlab program:

x1(1)=0;

y1(1)=0;

x2(1)=0;

y2(1)=0;

x3(1)=0;

y3(1)=0;

for i=1:10

x1(i+1)=0.5*x1(i);

y1(i+1)=0.5*y1(i);

x2(i+1)=0.5*x2(i)+0.25;

y2(i+1)=0.5*y2(i)+(sqrt(3)/4);

x3(i+1)=0.5*x3(i)+0.5;

y3(i+1)=0.5*y3(i);

end

figure

hold on

plot(x1,y1,'*')

plot(x2,y2,'*')

plot(x3,y3,'*')

hold off

Please kindly check attachment for output of 10, 100 and 1000 respectively.

The Sierpinski triangle can be implemented in MATLAB by plotting points iteratively-example-1
The Sierpinski triangle can be implemented in MATLAB by plotting points iteratively-example-2
The Sierpinski triangle can be implemented in MATLAB by plotting points iteratively-example-3
User Gyanendra Singh
by
5.1k points