\[ \begin{align}\begin{aligned}\newcommand\blank{~\underline{\hspace{1.2cm}}~}\\% Bold symbols (vectors) \newcommand\bs[1]{\mathbf{#1}}\\% Poor man's siunitx \newcommand\unit[1]{\mathrm{#1}} \newcommand\num[1]{#1} \newcommand\qty[2]{#1~\unit{#2}}\\\newcommand\per{/} \newcommand\squared{{}^2} \newcommand\cubed{{}^3} % % Scale \newcommand\milli{\unit{m}} \newcommand\centi{\unit{c}} \newcommand\kilo{\unit{k}} \newcommand\mega{\unit{M}} % % Percent \newcommand\percent{\unit{\%}} % % Angle \newcommand\radian{\unit{rad}} \newcommand\degree{\unit{{}^\circ}} % % Time \newcommand\second{\unit{s}} \newcommand\s{\second} \newcommand\minute{\unit{min}} \newcommand\hour{\unit{h}} % % Distance \newcommand\meter{\unit{m}} \newcommand\m{\meter} \newcommand\inch{\unit{in}} \newcommand\foot{\unit{ft}} % % Force \newcommand\newton{\unit{N}} \newcommand\kip{\unit{kip}} % kilopound in "freedom" units - edit made by Sri % % Mass \newcommand\gram{\unit{g}} \newcommand\g{\gram} \newcommand\kilogram{\unit{kg}} \newcommand\kg{\kilogram} \newcommand\grain{\unit{grain}} \newcommand\ounce{\unit{oz}} % % Temperature \newcommand\kelvin{\unit{K}} \newcommand\K{\kelvin} \newcommand\celsius{\unit{{}^\circ C}} \newcommand\C{\celsius} \newcommand\fahrenheit{\unit{{}^\circ F}} \newcommand\F{\fahrenheit} % % Area \newcommand\sqft{\unit{sq\,\foot}} % square foot % % Volume \newcommand\liter{\unit{L}} \newcommand\gallon{\unit{gal}} % % Frequency \newcommand\hertz{\unit{Hz}} \newcommand\rpm{\unit{rpm}} % % Voltage \newcommand\volt{\unit{V}} \newcommand\V{\volt} \newcommand\millivolt{\milli\volt} \newcommand\mV{\milli\volt} \newcommand\kilovolt{\kilo\volt} \newcommand\kV{\kilo\volt} % % Current \newcommand\ampere{\unit{A}} \newcommand\A{\ampere} \newcommand\milliampereA{\milli\ampere} \newcommand\mA{\milli\ampere} \newcommand\kiloampereA{\kilo\ampere} \newcommand\kA{\kilo\ampere} % % Resistance \newcommand\ohm{\Omega} \newcommand\milliohm{\milli\ohm} \newcommand\kiloohm{\kilo\ohm} % correct SI spelling \newcommand\kilohm{\kilo\ohm} % "American" spelling used in siunitx \newcommand\megaohm{\mega\ohm} % correct SI spelling \newcommand\megohm{\mega\ohm} % "American" spelling used in siunitx % % Inductance \newcommand\henry{\unit{H}} \newcommand\H{\henry} \newcommand\millihenry{\milli\henry} \newcommand\mH{\milli\henry} % % Power \newcommand\watt{\unit{W}} \newcommand\W{\watt} \newcommand\milliwatt{\milli\watt} \newcommand\mW{\milli\watt} \newcommand\kilowatt{\kilo\watt} \newcommand\kW{\kilo\watt} % % Energy \newcommand\joule{\unit{J}} \newcommand\J{\joule} % % Composite units % % Torque \newcommand\ozin{\unit{\ounce}\,\unit{in}} \newcommand\newtonmeter{\unit{\newton\,\meter}} % % Pressure \newcommand\psf{\unit{psf}} % pounds per square foot \newcommand\pcf{\unit{pcf}} % pounds per cubic foot \newcommand\pascal{\unit{Pa}} \newcommand\Pa{\pascal} \newcommand\ksi{\unit{ksi}} % kilopound per square inch \newcommand\bar{\unit{bar}} \end{aligned}\end{align} \]

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#

  1. 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.

  2. Open the data file Data_pool_info.csv and review the information it contains.

  3. In the INITIALIZATION section of the function:

    1. Import the data. Remove any header lines. Copy each data column into a separate variable.

    2. Initialize the community sanitation code requirements

    3. Perform error checking on the function inputs which prints an error message to the Command Window and exits the function if:

      1. The max number of swimmers allowed is not a scalar whole number greater than 0.

      2. The dive indicator value is not a scalar 1 or 0.

  4. In the CALCULATIONS section of the function:

    1. 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.

    2. 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.

    3. With the smallest allowable pool capacity that you found,

      1. Find the corresponding length, width, and depth from the data set.

      2. 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.

      3. Calculate the minimum total pumping capacity needed to recirculate the water (gal/min).

      4. Calculate the number of inlets needed to circulate the water. Hint: this must be a positive integer.

  5. In the FORMATTED TEXT & FIGURE DISPLAYS section of the function, write fprintf statements to display the following information in the MATLAB Command Window:

    1. The volume of the pool selected, with appropriate units.

    2. The maximum number of swimmers the selected pool can allow at one time.

    3. The minimum total pumping capacity needed to recirculate the water.

    4. 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.

  1. 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.

Table 15.3 Test Cases#

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]

  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.

  2. Submit all of your deliverables to Gradescope.

Sample Output#

Use the values in Table 15.4 below to test your program.

Table 15.4 Test Cases#

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