Answered step by step
Verified Expert Solution
Question
1 Approved Answer
a) What mathematical function is being performed by this function (i.e., if we call facto(5), what is the mathematical name of the operation f(5))? b)
a) What mathematical function is being performed by this function (i.e., if we call facto(5), what is the mathematical name of the operation f(5))? b) The cantor set is a very simple example of self-similarity (see for example the picture at http://mathforum.org/mathimages/index.php/Cantor_Set). It's really straight forward to draw, too, using recursion. Basically, each next row looks like the previous row, but the middle third is removed (look at nxl and nx2). Here's a Matlab function that draws the first two lines of the cantor set (x would be a two-value argument of x-positions for a line, and y would be a two-value argument for y-positions of a line. I have provided you with two scripts/functions: cantor lame.m (the function below) and test.m. Based on the cantor lame function as well as the example above, rewrite the function to plot lines in the cantor set using recursion. Note that you need to stop your code from recursing at some point! Allow the function cantor lame) to accept a third argument num that specifies how many lines to print (i.e., stops the recursion at some point). Try it out with num-6 function cantor_lame (x,y) % Plot the first row of the cantor set plot (x,y, 'r' ); % length of the line xlenn (x(2)-x(1); % What do these lines do? nxl- [x(1) x(1)+xlenn/3]; nx2- [x(1)+2*xlenn/3 x (2)]; % Plot the next row of the cantor set plot (maybe % you want to replace the next part with recursive % calls?) plot (nxl,y+l,'r'); plot (nx2,y+l,'r'); end Here's a test script to save to a different file, test.m, in order to test your version of cantor lame0: % test1.m x= [ 1 5]; figure(1) clear (1); hold on; cantor lame (X,y); hold off
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started