Oct 24, 2024 | 588 words | 6 min read
15.2.3. Task 3#
Learning Objectives#
Utilize if-else statements in MATLAB; Explore nested conditional structures
Task Instructions#
Open the
ENGR133_MATLAB_UDF_Template.m
MATLAB template and fill out the header information. Then save the file as ma4_team_3_teamnumber.m. You will write a function that has two inputs (number of swimmers, diving board indicator), zero outputs, and displays the information described below.Open the data file
Data_pool_info.csv
and review the information it contains.In the INITIALIZATION section of the function:
Import the data. Remove any header lines. Copy each data column into a separate variable.
Initialize the community sanitation code requirements
Perform error checking on the function inputs which prints an error message to the Command Window and exits the function if:
The max number of swimmers allowed is not a scalar whole number greater than 0.
The dive indicator value is not a scalar 1 or 0.
In the CALCULATIONS section of the function:
Calculate the required amount of surface area for the input number of swimmers. Return an error message if the input number of swimmers exceeds the number of swimmers that can be in the largest pool in the data file.
Use the input number of swimmers and the diving board indicator to identify the smallest allowable pool capacity (gal) from the data set that meets the community standards.
With the smallest allowable pool capacity that you found,
Find the corresponding length, width, and depth from the data set.
Find the maximum number of swimmers who can use the pool at once. Note: this may be different than the number of swimmers in the input argument.
Calculate the minimum total pumping capacity needed to recirculate the water (gal/min).
Calculate the number of inlets needed to circulate the water. Hint: this must be a positive integer.
In the FORMATTED TEXT & FIGURE DISPLAYS section of the function, write
fprintf
statements to display the following information in the MATLAB Command Window:The volume of the pool selected, with appropriate units.
The maximum number of swimmers the selected pool can allow at one time.
The minimum total pumping capacity needed to recirculate the water.
The number of inlets needed to circulate water back into the pool.
**Sample output for test case ** – valid number of swimmers and dive indicator (195,1)
The selected pool capacity is 254000 gallons. The maximum number of swimmers who can use the pool at one time is 243. The minimum pumping capacity is 529.2 gal/min. The pool requires 36 inlets to circulate the water.
Run your function for the following test cases as inputs and copy and paste each function call and
fprintf
output from the command window into the comment statements in the COMMAND WINDOW OUTPUT section of your script.
Test Case Description Input 1: |
Number of swimmers |
Input 2: Diving indicator |
---|---|---|
Valid number of swimmers and dive indicator |
195 |
1 |
Valid number of swimmers and dive indicator |
80 |
0 |
Invalid value for number of swimmers |
[100 200] |
1 |
Invalid value for number of swimmers |
-50 |
1 |
Invalid value for number of swimmers |
45.5 |
1 |
Invalid value for number of swimmers |
600 |
1 |
Invalid value for diving indicator |
100 |
2 |
Invalid value for diving indicator |
100 |
[0 1] |
Publish your function as a PDF for the test case (195,1) and name it ma4_team_3_teamnumber.m. Click here for more help publishing.
Submit all of your deliverables to Gradescope.
Sample Output#
Use the values in Table 15.4 below to test your program.
Case |
Number of Swimmers |
Diving Indicator |
---|---|---|
1 |
195 |
1 |
Ensure your program’s output matches the provided samples exactly. This includes all characters, white space, and punctuation. In the samples, user input is highlighted like this for clarity, but your program should not highlight user input in this way.
Case 1 Sample Output
>> ma4_team_3_teamnumber {Not enough input arguments.
Error in solution (line 23) if ~isscalar(numSwims) || (rem(numSwims,1)~=0 || numSwims <= 0) }
TODO: sample output error - likely change function from “main” to matlab function name