Question: This is my code for matlab for the sierpinski triangle. When I run the code for more than 6 iteration the image looks the same.

This is my code for matlab for the sierpinski triangle.

When I run the code for more than 6 iteration the image looks the same. Why is this?

Also, how can I get my image to be colored?

function sierpinski(A, B, C, iter)

if iter == 0

fill([A(1), B(1), C(1)], [A(2), B(2), C(2)], [0.5,0.5,0.5]);

hold on

else

sierpinski (A,(A+B)/2, (A+C)/2, iter-1);

sierpinski (B,(B+A)/2, (B+C)/2, iter-1);

sierpinski (C,(C+A)/2, (C+B)/2, iter-1);

end

>> sierpinski ([0,1], [100,10],[90,1],10)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!