M3_Decision Structures

.pdf

School

University of California, Los Angeles *

*We aren’t endorsed by this school

Course

331

Subject

Mechanical Engineering

Date

Dec 6, 2023

Type

pdf

Pages

5

Uploaded by EarlMetalLion28

Report
1 Assignment M-3_ Matlab Decision Structures (Individual, 30 points) Overall Purpose This assignment introduces you to the use of decision or conditional structures. These structures allow you to select values that meet a stated condition, and employ relational operators in if- else-end, if-elseif-else-end and other combinations of statements. These statements test a Boolean expression, then determine what action to take, depending on the true or false result. You will write and run a separate Matlab script for each of the following problems. Description Solve each of the following problems by writing and running Matlab scripts. Interpret the results for each problem, and answer the questions in Problem 2. Please include the following for each problem: 1. A brief statement explaining the problem (1-2 sentences) 2. The listing of your code (copy and paste your script into your word processor with the source formatting). Please be sure to enter a sufficient number of comments for each major block of the code. 3. A screen capture of each requested sample run with the requested values, showing the command window and the workspace. These must be legible. 4. Please create one pdf file to include all of the information from #1 through #4 for both problems. 5. Hints for more efficient programming: a. Choose descriptive variable names. Names like MainMass and AlbumSales are easier for others to understand than x, y, z, etc. b. The “Snipping Tool” or “Snip & Sketch” (use your Windows search bar to find it) are good ways to create readable screenshots. c. Use clear and clc commands at the beginning of your program to clear the workspace and the command window priori to running your program. Problem 1: WAR Calculator After getting to know your randomly assigned suitemates, you realize they are all big baseball fans. They decide that a good way of bonding would be to start a fantasy baseball league together. Unfortunately for you, baseball is not your sport. Since you don’t know much about it, you decide to make a code that will decipher some statistics for you so you can still pick good players. You build a code that sorts players based on their Wins Above Replacement (WAR) score. Your program should: Request that the user input a player’s WAR score
2 Use a conditional structure to determine the value of the player based on their WAR, with ranges given in the table on the next page: WAR Quality < 1 Scrub >= 1 & < 2 Role player >= 2 & < 3 Solid starter >= 3 & < 4 Good player >= 4 & < 5 All Star >= 5 & < 6 Superstar >= 6 MVP Given the user-inputted WAR score, have the program print the player’s quality as a full sentence using the fprintf command (See Week 10A and 10B slide set for examples of fprintf syntax) Run the program and take Command Window screenshots of the results for WAR scores of 2.7 and 5.1, respectively. Please note that these values should be entered in the command window when you run the program, and should not be hard-coded into the program itself. Problem 2: Methane Sensor Methane gas is an explosion risk at or above a 5% concentration. You are developing a mine ventilation mechanism to maintain safe levels of methane into a space into which the gas often leaks. Create a Matlab program that will take a concentration of methane in parts per million (ppm), and determine the appropriate air ventilation rate in m 3 /s. Your program should: 1. Ask the user to input a methane concentration in ppm 2. Use a conditional structure to determine a ventilation rate, using the following table:
3 Concentration (ppm) Ventilation Rate (m 3 /s) 0 =< ppm < 5000 5 5000 =< ppm < 20000 10 20000 =< ppm < 40000 20 40000 =< ppm < 50000 40 50000 =< ppm 80 3. Using the fprintf command, output the required ventilation rate. Do not forget to specify that the output number is the ventilation rate and that its units are m 3 /sec. 4. Issue an emergency evacuation warning if the methane levels indicate an explosion risk (>=50000 ppm). Use a short phrase, such as DANGER! or LEAVE NOW! Create sample runs for 25000 ppm and 65000 ppm (should return 20 and 80 m 3 /s, respectively). Deliverables for this assignment: 1. .m file for Problem 1, named as M3_Problem1_YourPID.m 2. .m file for Problem 2, named as M3_Problem2_YourPID.m 3. A single .pdf file with an appropriate file name, containing: Your name, class section, etc. For each problem, a brief statement explaining the problem (1-2 sentences) The listing of your code (copy and paste your script into your word processor with the source formatting, i.e., such that the color and font formatting of the pasted code is the same as it appears in Matlab). A screen capture of each requested sample run with the requested values, showing the command window and workspace. These must be legible. File naming convention: YourPID_M3_summary.pdf Rubric The rubric for this assignment is given on the next two pages.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help