Question: Create a function to generate and plot the Sierpinski's triangle with side length 1 and user - defined iteration numbers. Define your function output and

Create a function to generate and plot the Sierpinski's triangle with side length 1 and user-defined iteration numbers. Define your function output and name as
[x,y]= sierpinski(N)
where N is the number of iterations. x,y are the output of your function, which are the x and y coordinates of the scattered points forming the triangular shapes.
In your function, first, create x and y zeros vectors of the length N.
Second, use for-loop to iterate from 2 to N, and generate a random number from {0,1,2} and assign it to variable c at the beginning of each step.
Third, in each step, implement the switch-case statements. Use the variable c as the switch expression, and use integer 0,1 and 2 as case expressions.
In case 0,dox(i)=0.5*x(i-1);y(i)=0.5*y(i-1).
In case 1,dox(i)=0.5*x(i-1)+0.25;y(i)=0.5*y(i-1)+324.
In case 2,dox(i)=0.5*x(i-1)+0.5;y(i)=0.5*y(i-1).
Last but not least, plot your x and y vectors to obtain the Sierpinski's triangle similar to the following illustration.
 Create a function to generate and plot the Sierpinski's triangle with

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!