ENGR 132 Spring 2020 Page 1 of 5 A10 · Complex Loops Instructions 1. Read each problem carefully. You are responsible for following all instructions within each problem. 2. Review the grading...

description below


ENGR 132 Spring 2020 Page 1 of 5 A10 · Complex Loops Instructions 1. Read each problem carefully. You are responsible for following all instructions within each problem. 2. Review the grading flowchart for each problem in this assignment. These explain how your work will be graded. 3. Use the problem-specific m-file templates provided in the assignment file. Name your m-files to match the format in the table below, where login is your Purdue Career Account login. Item Type Deliverables Problem 1: Tank Volume Without Loop Individual  A10_noloop_sphereVol_login.m Problem 2: Greatest Common Factor Individual  A10_GCD_login.m  A10_GCD_tracking_login.docx Problem 3: Pipe Velocities Individual  A10_pipeVel_login.m Gradescope Submission Individual  A10_login.pdf 4. Read the submission instructions on the last page of this assignment. Notes Before You Begin this Assignment Helpful MATLAB Commands Learn about the following built-in MATLAB commands, which might be useful in your solutions: function, rem, any, all ENGR 132 Spring 2020 Page 2 of 5 Problem 1: Tank Volume Without Loop Deliverable Function: A10_noloop_sphereVol_login.m Problem In A09 Problem 1, you wrote a function that used a for loop to determine a volume model for fluid inside a spherical tank. For this problem, replace the loop with vector operations. • Have a complete function header; • Accept 1 input arguments: tank radius in centimeters; • Return 0 output arguments; • Use vector operations to calculate a vector of volume values from 0 cm (empty tank) to the diameter (full tank) at 100 equal height increments; • Display the volume model on a professionally formatted plot; • Only calculate a vector of volumes if the tank radius is between 100 and 500 cm, inclusive; o Display a meaningful message if a radius is selected outside this range. o Do not display a plot if the volume vector is not calculated. Publish to PDF for Submission Publish your tank volume function to PDF using the radius of 250 cm. ENGR 132 Spring 2020 Page 3 of 5 Problem 2: Greatest Common Divisor Deliverable Script: A10_GCD_login.m Tracking Table: A10_GCD_tracking_login.docx Problem Finding the greatest common divisor (GCD) of large numbers has an important role in cyber security. For this problem, you need to calculate the GCD between each element in one vector compared to a constant single value. For example, you have a number 525 and need to find the GCD between it and each number in the vector [3060 1525 10]. You will create a resulting vector that contains [GCD (3060,525) GCD (1525,525) GCD (525,10)]. A straightforward way to calculate the GCD is to use the Euclidean Algorithm. Khan Academy has a good explanation. You will create a script that uses the Euclidean Algorithm to determine the GCD between to numbers and follows this flowchart: Start Set scalar for calculating GCD. For testing, set 525 to a variable named B Set a vector for calculating GCD. For testing, set values to 3060, 1525, and 10 Set A_val equal to the value of A at the linear index location of the current index Find the larger value between A_val and B, and assign to variable larger Find the smaller value between A_val and B, and assign to variable smaller Is the remainder value not 0? Reset larger to equal the value in smaller Reset smaller to equal the value in remainder Find the remainder of larger divided by smaller and assign the value to variable remainder Assign the value in smaller to vector GCD in the appropriate indexed location Preallocate vector named GCD with zeros and with the same dimensions as vector A Find the remainder of larger divided by smaller and assign the value to variable remainder Increment the index by 1 Index = 1 Is the index less than or equal to the number of elements in A? Display vector GCD Stop Yes No Yes No Part A: Complete the tracking table for the loops using the initial values shown in the flowchart. Part B: Complete the code. Debug and make sure it matches the flowchart. Publish to PDF for Submission Set the vector A to [5883817, 6719543852, 315, 124814874] and variable B to 523815. Then publish to PDF. https://www.khanacademy.org/computing/computer-science/cryptography/modarithmetic/a/the-euclidean-algorithm ENGR 132 Spring 2020 Page 4 of 5 Problem 3: Pipe Fluid Velocities Deliverable Function: A10_pipeVel_login.m Problem A pipe manufacturer is trying to understand the effects of changing the inner and outer diameters of a pipe system on the velocity of fluid through the pipe. The figure shows the schematic of pipe configuration consisting of a solid rod in the center of a hollow outer pipe. Fluid flows through the hollow part of the outer pipe. The manufacturer can vary both the internal diameter of the outer pipe and the diameter of the solid inner rod. They want you to create a function that will determine the velocity of a fluid moving through the pipe for different configurations. You can predict the velocity using the mass flow rate equation: �̇�? = ?????? Where �̇�? is a fixed mass flow rate of 2 kg/s, ?? is the fluid density at 1000 kg/m3, ?? is the fluid velocity in m/s, and ?? is the cross-sectional area of the hollow region of the pipe system. The function should return only pipe systems that maintain velocities below 300 m/s. The function must • Accept 2 input arguments: one vector of outer pipe diameters, ??????????, (m) and one vector of corresponding inner pipe diameters, ???????? , (m). o Note: these vectors can have different dimensions from each other. • Gives meaningful error message(s) if any outer pipe or rod diameter is 0 or smaller. o If an error message is produced, then the function returns an output argument of [-1 -1] and stops trying to find valid configurations. Reminder: do not use the break command. • Uses nested FOR loops to calculate the fluid velocity for each possible combination of outer and inner pipe diameter values. • Return 1 output argument: one Nx2 array that contains valid combinations of outer pipe diameters in Column 1 and inner rod diameters in Column 2 that maintain fluid velocity greater than 0 m/s but slower than 300 m/s. Run your function for these test cases, keeping the function call unsuppressed. Copy and paste your function call and output results to RESULTS for each test: Outer Diameter vector, ?????????? , (m) Inner Rod Diameter vector, ???????? , (m) 0.01:0.01:0.05 0.03:0.02:0.09 [5 10 3] [0 1 2 3 4] [5 8 10] [2 4] Publish to PDF for Submission Publish your function as a PDF using the last entry in the table above. Suppress your function call when you publish. ENGR 132 Spring 2020 Page 5 of 5 How to Submit Your Work After you complete the assignment and are ready to submit your work, 1. Merge the problem PDFs into a single PDF file. Name that file A10_login.pdf. 2. Log into Gradescope and submit A10_login.pdf to the A10 assignment. Indicate which pages correspond each problem. Failure to tag the problems appropriately will result in your work losing credit for all wrongly tagged problems. 3. Log into Blackboard and submit all deliverable files to the A10 Dropbox.  A10_noloop_sphereVol_login.m  A10_GCD_login.m  A10_pipeVel_login.m  A10_login.pdf Failure to submit these files to Blackboard may result in 0 for the assignment. A10 ∙ Complex Loops Instructions Notes Before You Begin this Assignment Helpful MATLAB Commands Problem 1: Tank Volume Without Loop Deliverable Problem Publish to PDF for Submission Problem 2: Greatest Common Divisor Deliverable Problem Publish to PDF for Submission Problem 3: Pipe Fluid Velocities Deliverable Problem Publish to PDF for Submission How to Submit Your Work %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % ENGR 132 % Program Description replace this text with your program decription as a comment % % Assignment Information % Assignment: PS ##, Problem # % Author: Name, [email protected] % Team ID: ###-## % Academic Integrity: % [] I worked with one or more peers but our collaboration % maintained academic integrity. % Peers I worked with: Name, login@purdue [repeat for each] did you complete the assignment information? delete this line if yes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% ____________________ %% INITIALIZATION %% ____________________ %% CALCULATIONS %% ____________________ %% FORMATTED TEXT/FIGURE DISPLAYS %% ____________________ %% ACADEMIC INTEGRITY STATEMENT % I have not used source code obtained from any other unauthorized % source, either modified or unmodified. Neither have I provided % access to my code to another. The script I am submitting % is my own original work. A11 ∙ Complex Loops Problem 2: Greatest Common Divisor Tracking Table Complete this tracking table to predict the GCD vector when A = [3060 1525 10] B = 525 Only complete the cells that are white. Outer Iteration Larger value Smaller value Rem Inner iteration Larger Smaller Rem GCD vector -- -- -- -- -- -- -- -- [0 0 0] 1 3060 525 435 1 525 435 90 [0 0 0] 2 435 90 75 3 4 2 1 2 3 3 1 replace this text with your function definition line %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % ENGR 132 % Program Description %Replace the loop function in A09 problem 1 with vector operations to %determine a volume model for fluid inside a spherical tank. % Function Call replace this text with a comment that states the function call % % Input Arguments replace this text with a commented list of the input arguments % % Output Arguments replace this text with a commented list of the output arguments % % Assignment Information % Assignment: PS 10, Problem 01 % Author: Hailey Ko, [email protected] % Team ID:
Feb 25, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here