Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please show me the appropriate script I must create to properly execute the func

ID: 3552477 • Letter: P

Question

Please show me the appropriate script I must create to properly execute the function! Cheers!


Create a graphical user interface (GUI) allowing for the display and control of the Sierpinski and Barnsley fractals. Use the graphical user interface development environment (guide) to create a graphical user interface with the following properties. Your interface will provide (1) a plotting area, (2) a widget that allows the user to select, which target algorithm to run (Sierpinski, Sierpinski Recursive, Barnsley), (3) provide a means to turn grid lines as well as hold on/off, (4) allow for input of fractal specific parameters, and (5) for the plotting area to be cleared. These parameters will include the number of iterations, the number of recursions and the three triangle vertices when appropriate. It should also be possible to (6) select the pomt color and style to be used. There also should be an option to (7) show progressive as well as aggregate rendering, i.e. a button to specify that each pomt should be rendered as soon as it has been computed, versus plotting being deferred until the computation of all pomts is complete. The later will result m a major performance boost and you may label this toggle button "Performance Boost". The name of your gui and the associated m file should be "finalGUT'.

Explanation / Answer

In a file in your working folder, create a function in the file sierpinski.m. This function returns a matrix representing an image of a Sierpinski carpet fractal. It takes as input the fractal level and an optional data type.


function carpet = sierpinski(nLevels,classname)

if nargin == 1

classname = 'single';

end


mSize = 3^nLevels;

carpet = ones(mSize,classname);


cutCarpet(1,1,mSize,nLevels); % begin recursion


function cutCarpet(x,y,s,cL)

if cL

ss = s/3; % define subsize

for lx = 0:2

for ly = 0:2

if lx == 1 && ly == 1

% remove center square

carpet(x+ss:x+2*ss-1,y+ss:y+2*ss-1) = 0;

else

% recurse

cutCarpet(x + lx*ss, y + ly*ss, ss, cL-1);

end

end

end

end

end

end

Create TestCarpet Test Class


In a file in your working folder, create a new class, TestCarpet, to test the sierpinski function.


classdef TestCarpet < matlab.unittest.TestCase

Define properties Block


Define the properties used for parameterized testing. In the TestCarpet class, define these properties in a property block with the TestParameter attribute.


properties (TestParameter)

type = {'single','double','uint16'};

level = struct('small', 2,'medium', 4, 'large', 6);

side = struct('small', 9, 'medium', 81,'large', 729);

end

The type property contains the different data types you want to test. The level property contains the different fractal level you want to test. The side property contains the number of rows and columns in the Sierpinski carpet matrix and corresponds to the level property. To provide meaningful names for each parameterization value, level and side are defined as structs.


Define Test methods Block


Define the following test methods in the TestCarpet class.


methods (Test)

function testRemainPixels(testCase, level)

% expected number pixels equal to 1

expPixelCount = 8^level;

% actual number pixels equal to 1

actPixels = find(sierpinski(level));

testCase.verifyNumElements(actPixels,expPixelCount);

end

  

function testClass(testCase, type, level)

testCase.verifyClass(...

sierpinski(level,type), type);

end

  

function testDefaultL1Output(testCase)

exp = single([1 1 1; 1 0 1; 1 1 1]);

testCase.verifyEqual(sierpinski(1), exp);

end

  

end

The testRemainPixes method tests the output of the sierpinski function by verifying that the number of nonzero pixels is the same as expected for a particular level. This method uses the level property and, therefore, results in three test elements

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote