Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems Second East European Symposium Adbis 98 Poznan Poland September 1998 Proceedings Lncs 1475

Authors: Witold Litwin ,Tadeusz Morzy ,Gottfried Vossen

1st Edition

3540649247, 978-3540649243

More Books

Students also viewed these Databases questions