Write MATLAB function called sierpinskicarpet.m to draw the Sierpinski Carpet. T
ID: 3827227 • Letter: W
Question
Write MATLAB function called sierpinskicarpet.m to draw the Sierpinski Carpet. The function must be able to be invoked as follows: >> x = 60; >> y = 60: >> w = 120; >> sierpinski carpet (x, y, w); Here, x and y indicate (x, y) coordinates of the centre of the initial square, while w specifies the length of the sides of the initial square. Upon completion the function will plot the Sierpinski Carpet according to the specified You must set the correct b Se case such that your program can terminate successfully. It might be wise conservative base case to establish how deep a recursion your handle. how deep a recursion your Once you are done, show your to get marked off. Figure 1. The construction of the fractal is defined recursively as follows: Start with a square. Shrink the square such that the width and height of the shrunken square are both 1/3 of the width and height of the original square. Make 8 copies of the shrunken square and place them in the original square such that one side of each copy fully touches the perimeter of the original square. For each copy of the shrunken square repeat steps 2 to 4 until the base case is encountered.Explanation / Answer
Matlab code :
tic and toc : watch timers
function Sierpinski(i);
switch nargin
case 0
i=5;
end
tic
M = 0;
for k=1:i
M = [M, M, M;
M, ones(3^(k-1)), M;
M, M, M];
end
imagesc(M);
colormap(gray);
axis equal;
axis off;
toc
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.