\[ \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} \]

Dec 03, 2024 | 613 words | 6 min read

15.2.3. Task 3#

Learning Objectives#

Utilize if-else statements in MATLAB; Explore nested conditional structures

Introduction#

Engineers work on municipal projects, such as community pool construction. You must write a user-defined function that will display information about the requirements for a new community pool project. Your function will use programming to select and display information about the smallest allowable swimming pool that will meet a community’s needs. Each pool has the same geometry: a simple rectangular surface with a deeper end at one end of the pool. A data file named Data_pool_info.csv contains information for several pool sizes. The community sanitation code has the following requirements:

  • Surface area per swimmer in the pool: \(\qty{25}{\foot\squared}\)

  • Minimum diving depth (only for pools with diving boards installed): \(\qty{10}{\foot}\)

  • Number of times that the water must be recirculated through the filter: \(3 \text{ times/day}\)

  • Flow rate through inlets that push water back into the pool from the recirculation pump: \(\qty{15}{\gallon\per\minute}\)

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 (\(\gallon\)) 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 (\(\gallon\per\minute\)).

      4. Calculate the number of inlets needed to circulate the water.

        Hint

        The number of inlets 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.

  6. Run your function for the 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.

  7. Publish your function as a PDF for the test case \((195,1)\) and name it ma4_team_3_teamnumber.pdf. Click here for more help publishing.

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

2

80

0

3

[100 200]

1

4

-50

1

5

45.5

1

6

600

1

7

100

2

8

100

[0,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(195, 1) The selected pool volume 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.

Case 2 Sample Output

>> ma4_team_3_teamnumber(80, 0) The selected pool volume is 120000 gallons. The maximum number of swimmers who can use the pool at one time is 108. The minimum pumping capacity is 250.0 gal/min. The pool requires 17 inlets to circulate the water.

Case 3 Sample Output

>> ma4_team_3_teamnumber([100 200], 1) {Error using solution (line 26) The number of swimmers must be a scalar whole number greater than zero. }

Case 4 Sample Output

>> ma4_team_3_teamnumber(-50, 1) {Error using solution (line 26) The number of swimmers must be a scalar whole number greater than zero. }

Case 5 Sample Output

>> ma4_team_3_teamnumber(45.5, 1) {Error using solution (line 26) The number of swimmers must be a scalar whole number greater than zero. }

Case 6 Sample Output

>> ma4_team_3_teamnumber(600, 1) {Error using solution (line 62) The number of swimmers exceeds the largest pool size. Select a smaller number of swimmers. }

Case 7 Sample Output

>> ma4_team_3_teamnumber(100, 2) {Error using solution (line 32) Enter 1 if diving is allowed or a 0 if diving is not allowed }

Case 8 Sample Output

>> ma4_team_3_teamnumber(100, [0,1]) {Error using solution (line 32) Enter 1 if diving is allowed or a 0 if diving is not allowed }