Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(MECHANICAL ENGINEERING AND/OR COMPUTER SCIENCE SUBJECT) (HEAVY USE OF ISO METRIC BLOCKS AS WELL AS CODING ON MATLAB) Please do all four parts, I will

(MECHANICAL ENGINEERING AND/OR COMPUTER SCIENCE SUBJECT)

(HEAVY USE OF ISO METRIC BLOCKS AS WELL AS CODING ON MATLAB)

Please do all four parts, I will upvote :)!

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Summary: Draw isometric images and then use a conditional statement("if") to select between one configuration and another in MATLAB Introduction: The lab is divided up into four parts: Part 1: Practice writing a simple function that accepts Input and writes to the screen Part 2: Practice an if-elseif-else structure within a function Part 3: Draw a multiple Lego using patches Part 4: Use 1f-elself-else to choose whether to add a new block to your lego Image. Figure 1. An example of the Lego block arrangement that you'll draw. A one-by-four block is assumad to be one unit wide one unit high and four units long a Lab Instructions Part 1: Create a function in a MATLAB script (.m file) that incorporates a user input (from the Command Window) and creates plots based on what the user input. Look at the following as an example of a file that has the same name as the function that is written in the MATLAB editor. Notice how it has an input variable (in parentheses) and that I can call the function from the command window, with a value for that input variable. Page 14 fo MATLAR 3- function my_neat_function(myinput_variable) fprintf("Hy variable has the value ad ',myinput_variable) end >> ny_nest_function(2) My variable has the value 2 Figure 2. A function defined in the editor and colled from the command window. Note that the file name and function name are the same. They have to be! Do something similar for this part of the lab. Part 2: Type in the following code for the if-elseif statement. Try it out from the command Window. See if you can make the different plots show up via commands from the Command Window. DOWN 2 3 4 5 6 7 9 10 11 12 function mynewprogram(myvariable) This is a simple function, written in a file called mynewprogram it takes the input variable, myvariable, and runs it through an statement. Example usage from MATLAB >> mynewprogram (1) this will input number 1 into the fun if (myvariable -- 1) If the variable equals 1, then execute th figure(1); set up the f plot([1 2 3 4]. (10 100 300-22]); first plot title('Plot 1: The user input the number 1); title on fir elseif (myvariable - 2) If variable equals 2, then execute the figure(1): set up the plot([10 20 30 401, 40 50 60 80]); second plot title('Plot 2: the user input the number 2'); title on 2nd else this is the default. Execute the next line if the user didn't choose 1 or 2 disp('error! The user selected a wrong number. Choose 1 or 2n end end of the if-elseif structure end end of the function. 16 17 18 19 20 21 Figure 3. Example felsef MATLAB script called mynewprogram.m. You call the function from the command window in MATLAB: >> mynewprogram (2) Enter Part 3: Draw the Lego blocks in MATLAB Sketch the Lego by hand using isometric dot paper. Leave enough space for a second sketch from Part 4, beside the first one. Now draw the Lego using MATLAB. Refer to the posted video that describes how to do this using the Patch function in MATLAB. The video descrbes a more difficult task of drawing in MATLAB... the Lego blocks are easier. Remember that we consider the mapping of the Lego blocks to be as follows: for a one-by-four block, it's one unit wide, one unit high and four units deep. One unit corresponds to the space between two dots in the isometric paper and the distance between whole numbers (1 and 2 or 15 and 16, for instance) in MATLAB Make sure to use the following two commands to get the axis proportions correct and to get the automatic orientation of the shape (view from above and to the side: 1.e. three-quarter view"): axis('equal') view (I-1 -1 1]) Part 4: Change the Lego drawing in MATLAB using a conditional statement Create a function file called "mylegodrawing.m" in MATLAB that accepts input from the command line. You will draw the Lego blocks from Part 3 if the user enters mylegodrawing (5) on the other hand, if the user enters mylegodrawing (3) then you should draw the shape which applies to you in the table. Note that you don't need to draw the flat 4 by 6 black plate... We use it for reference and to hold your bricks together. Finally, if the user enters any other number (other than 5 or 3), then draw the Lego blocks entirely in black, using the shape from Part 3 Hint: Consider inserting the following code within the "if", "elseif", and "else" sections of your code, just before you call the "patch" function, as it will clear the figure and orient it properly: figure (1) clf (1, 'reset') axis ('equal') view ((-1 -1 1]) Summary: Draw isometric images and then use a conditional statement("if") to select between one configuration and another in MATLAB Introduction: The lab is divided up into four parts: Part 1: Practice writing a simple function that accepts Input and writes to the screen Part 2: Practice an if-elseif-else structure within a function Part 3: Draw a multiple Lego using patches Part 4: Use 1f-elself-else to choose whether to add a new block to your lego Image. Figure 1. An example of the Lego block arrangement that you'll draw. A one-by-four block is assumad to be one unit wide one unit high and four units long a Lab Instructions Part 1: Create a function in a MATLAB script (.m file) that incorporates a user input (from the Command Window) and creates plots based on what the user input. Look at the following as an example of a file that has the same name as the function that is written in the MATLAB editor. Notice how it has an input variable (in parentheses) and that I can call the function from the command window, with a value for that input variable. Page 14 fo MATLAR 3- function my_neat_function(myinput_variable) fprintf("Hy variable has the value ad ',myinput_variable) end >> ny_nest_function(2) My variable has the value 2 Figure 2. A function defined in the editor and colled from the command window. Note that the file name and function name are the same. They have to be! Do something similar for this part of the lab. Part 2: Type in the following code for the if-elseif statement. Try it out from the command Window. See if you can make the different plots show up via commands from the Command Window. DOWN 2 3 4 5 6 7 9 10 11 12 function mynewprogram(myvariable) This is a simple function, written in a file called mynewprogram it takes the input variable, myvariable, and runs it through an statement. Example usage from MATLAB >> mynewprogram (1) this will input number 1 into the fun if (myvariable -- 1) If the variable equals 1, then execute th figure(1); set up the f plot([1 2 3 4]. (10 100 300-22]); first plot title('Plot 1: The user input the number 1); title on fir elseif (myvariable - 2) If variable equals 2, then execute the figure(1): set up the plot([10 20 30 401, 40 50 60 80]); second plot title('Plot 2: the user input the number 2'); title on 2nd else this is the default. Execute the next line if the user didn't choose 1 or 2 disp('error! The user selected a wrong number. Choose 1 or 2n end end of the if-elseif structure end end of the function. 16 17 18 19 20 21 Figure 3. Example felsef MATLAB script called mynewprogram.m. You call the function from the command window in MATLAB: >> mynewprogram (2) Enter Part 3: Draw the Lego blocks in MATLAB Sketch the Lego by hand using isometric dot paper. Leave enough space for a second sketch from Part 4, beside the first one. Now draw the Lego using MATLAB. Refer to the posted video that describes how to do this using the Patch function in MATLAB. The video descrbes a more difficult task of drawing in MATLAB... the Lego blocks are easier. Remember that we consider the mapping of the Lego blocks to be as follows: for a one-by-four block, it's one unit wide, one unit high and four units deep. One unit corresponds to the space between two dots in the isometric paper and the distance between whole numbers (1 and 2 or 15 and 16, for instance) in MATLAB Make sure to use the following two commands to get the axis proportions correct and to get the automatic orientation of the shape (view from above and to the side: 1.e. three-quarter view"): axis('equal') view (I-1 -1 1]) Part 4: Change the Lego drawing in MATLAB using a conditional statement Create a function file called "mylegodrawing.m" in MATLAB that accepts input from the command line. You will draw the Lego blocks from Part 3 if the user enters mylegodrawing (5) on the other hand, if the user enters mylegodrawing (3) then you should draw the shape which applies to you in the table. Note that you don't need to draw the flat 4 by 6 black plate... We use it for reference and to hold your bricks together. Finally, if the user enters any other number (other than 5 or 3), then draw the Lego blocks entirely in black, using the shape from Part 3 Hint: Consider inserting the following code within the "if", "elseif", and "else" sections of your code, just before you call the "patch" function, as it will clear the figure and orient it properly: figure (1) clf (1, 'reset') axis ('equal') view ((-1 -1 1])

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

Campaign Finance

Authors: Robert E. Mutch

1st Edition

0190274697, 9780190274696

More Books

Students also viewed these Finance questions

Question

Explain the different types of marketing strategies.

Answered: 1 week ago

Question

Explain product positioning.

Answered: 1 week ago

Question

Explain Industrial market segment.

Answered: 1 week ago