Question

In: Mechanical Engineering

Complete exercise 9.20 from the text. (a) Create a function called polygon that draws a polygon...

Complete exercise 9.20 from the text.

(a) Create a function called polygon that draws a polygon in a polar plot. Your function should have a single input parameter – the number of sides.

(b) Use a for loop to create a figure with four subplots…You should use the function you created in part (a) to draw each polygon. Use the index parameter from the for loop to specify the subplot in which each polygon is drawn, and in an expression to determine the number of sides used as input to the polygon fuction.

For help with the algorithm to draw regular polygons, consult problem 8.17 To be clear, the polygon() function should only draw one polygon, as specified by the number it receives as a parameter.

A second function or script should have the for loop, call subplot() to indicate where to create a plot, and call polygon() to actually create the plot.

Additional notes include:

1. There must be some weird junk on the internet because many previous students have tried to use some gibberish with rand() and cumsum() that does not create triangles, squares, etc. Do not repeat their mistakes.

2. Never clear variables at the start of a function!

3. A for loop with just one number is a waste of typed characters.

4. The instructions never mention prompting the user for a number.

5. You must call subplot before you plot anything that is supposed to go into a subplot.

6. Things that only need to be done once should not be inside a loop, such as set(gcf, …). The only things that should be inside a loop are the things that must be repeated.

7. If you copy and paste a few lines, especially more than once, there is probably a better way.

and here's what I did so far, it needs to be fixed according to note number 4 and additional corrections

%% 9.20 (a) create a function called polygon in a polar plot
function [p] = polygon(n)
n = input('Enter the number of sides: ');
theta = 0: 2*pi/n : 2*pi;
r = ones(1, length(theta));
subplot(2, 2, n-2); polar(theta, r);
end
% (b) use a for loop to create figure with four subplots
function polygon
for n = 3: 1: 6
polar(theta, r)
end

end

Thanks

Solutions

Expert Solution


Related Solutions

function exerciseOne(){ // Exercise One: In this exercise you will create a variable called 'aboutMe' //...
function exerciseOne(){ // Exercise One: In this exercise you will create a variable called 'aboutMe' // This variable should be assigned a new object // In this object create three key:value pairs // The keys should be: 'name', 'city', 'favoriteAnimal' // The values should be strings associated with the keys. // return the variable 'aboutMe' } function exerciseTwo(animal){ // Exercise Two: In this exercise you will be given an object called 'animal' // Create a new variable called 'animalName' //...
In Python Create a function called ℎ?????. The function has as arguments a list called ??????...
In Python Create a function called ℎ?????. The function has as arguments a list called ?????? and a list call center. • List ?????? contains lists that represent points. o For example, if ?????? = [[4,2], [3,2], [6,1]], the list [4,2] represents the point with coordinate ? at 4 and y coordinate at 2, and so on for the other lists. Assume that all lists within points contain two numbers (that is, they have x, y coordinates). • List ??????...
Exercise 9 – Writing values from a list into a file Complete the function design for...
Exercise 9 – Writing values from a list into a file Complete the function design for the write_most_frequent() function, which takes 4 parameters, a string, a list of tuples, an integer, and another string: • The first string represents the name of the file to write to (with the append usage mode) • The list of tuples contains the information to write. Assume the list has already been sorted. • The integer represents the number of elements to read from...
A polygon is called convex if every line segment from one vertex to another lies entirely...
A polygon is called convex if every line segment from one vertex to another lies entirely within the polygon. To triangulate a polygon, we take some of these line segments, which don’t cross one another, and use them to divide the polygon into triangles. Prove, by strong induction for all naturals n with n ≥ 3, that every convex polygon with n sides has a trian-gulation, and that every triangulation contains exactly n − 2 triangles. (Hint: When you divide...
First create the text file given below. Then complete the main that is given. There are...
First create the text file given below. Then complete the main that is given. There are comments to help you. An output is also given Create this text file: data1.txt -59 -33 34 0 69 24 -22 58 62 -36 5 45 -19 -73 62 -5 95 42 ` Create a project and a Main class and copy the Main class and method given below. First declare the array below the comments that tell you to declare it. Then there...
In Python Create a function called ????. The function receives a "string" that represents a year...
In Python Create a function called ????. The function receives a "string" that represents a year (the variable with this "String" will be called uve) and a list containing "strings" representing bank accounts (call this list ????). • Each account is represented by 8 characters. The format of each account number is "** - ** - **", where the asterisks are replaced by numeric characters. o For example, “59-04-23”. • The two central characters of the "string" of each account...
Create a project called rise. Add a class called GCD. Complete a program that reads in...
Create a project called rise. Add a class called GCD. Complete a program that reads in a numerator (as an int) and a denominator (again, as an int), computes and outputs the GCD, and then outputs the fraction in lowest terms. Write your program so that your output looks as close to the following sample output as possible. In this sample, the user entered 42 and 56, shown in green. Enter the numerator: 42 Enter the denominator: 56 The GCD...
in phyton programming: with numpy Create a function called biochild.  The function has as parameters...
in phyton programming: with numpy Create a function called biochild.  The function has as parameters the number m and the lists ??????h?? and ??????h??.  The lists ??????h?? and ??????h?? contain 0’s and 1’s.  For example: ??????h?? = [1,0,0,1,0,1] and ??????h?? = [1,1,1,0,0,1]  Both lists have the same length ?.  The 0's and 1's represent bits of information (remember that a bit is 0 or 1).  The function has to generate a new list (child)....
IN PYTHON Create a function called biochild.  The function has as parameters the number m...
IN PYTHON Create a function called biochild.  The function has as parameters the number m and the lists biomother and biofather.  The biomother and biofather lists contain 0’s and 1’s.  For example: biomother = [1,0,0,1,0,1] and biofather = [1,1,1,0,0,1]  Both lists have the same length n.  The 0's and 1's represent bits of information (remember that a bit is 0 or 1).  The function has to generate a new list (child).  The child...
Using Python create a script called create_notes_drs.py. In the file, define and call a function called...
Using Python create a script called create_notes_drs.py. In the file, define and call a function called main that does the following: Creates a directory called CyberSecurity-Notes in the current working directory Within the CyberSecurity-Notes directory, creates 24 sub-directories (sub-folders), called Week 1, Week 2, Week 3, and so on until up through Week 24 Within each week directory, create 3 sub-directories, called Day 1, Day 2, and Day 3 Bonus Challenge: Add a conditional statement to abort the script if...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT