Dec 03, 2024 | 386 words | 4 min read
12.2.3. Task 3#
Learning Objectives#
Practice writing simple arithmetic expressions in MATLAB.
Introduction#
A fuel tank is constructed in the shape of a cylinder. The design engineer that designed the tank provided the dimensions in meters. The construction engineer that is building the tank needs to know the capacity in U.S. gallons, as well as the dimensions in feet. Your goal is to write a MATLAB script that finds the volume of the cylinder in U.S. gallons, as well as the tank dimensions in feet.
Task Instructions#
Open the MATLAB Template (
ENGR133_MATLAB_Template.m
) and fill out the header information. Then save the file as ma1_team_3_teamnumber.m.Note
In the MATLAB Template, any initial given information will go under
INITIALIZATION
your main code will go underCALCULATIONS
and anydisp
orfprintf
commands will go underOUTPUTS
.Read through the calculation instructions for Tank 1 and Tank 2 (steps 3 & 4) and create a flowchart that shows the input, calculation (including unit conversions), and display process. Append your flowchart to ma1_team_teamnumber.pdf.
TANK 1: Assume the initial measurements are \(\qty{12}{\m}\) in diameter and \(\qty{5}{\m}\) tall. Be sure to comment your code adequately as you program.
a. Under
INITIALIZATION
, useclear
andclc
to remove any data and output from previous scripts. Then, list your initial measurements for tank 1. These should not display when your code is run. These values should be assigned and referenced as variables in the body of the code.b. Under
CALCULATIONS
, calculate the volume of the cylinder in gallons and assign it to a variable titledtank1_capacity
. Be careful with your unit conversions.c. Under
OUTPUTS
, display your final answers to the screen usingdisp
and a statement without a semicolon:disp('The capacity of Tank 1 in U.S. gallons is:') tank1_capacity
TANK 2: In the same MATLAB script, repeat steps a and b from TANK 1 to perform the same calculations for a second tank that is \(\qty{4}{\m}\) in diameter and \(\qty{9}{\m}\) tall. Then use
fprintf
to display the capacity in gallons and dimensions in feet as shown below. The capacity should be rounded to the nearest integer and dimensions to the nearest tenth.Publish your script as ma1_team_3_teamnumber.pdf.
Save your script as ma1_team_3_teamnumber.m.
Save your flowchart in ma1_team_teamnumber.pdf.
Sample Output#
Use the values in Table 12.4 below to test your program.
Case |
Tank 1: diameter |
Tank 1: height |
Tank 2: diameter |
Tank 2: height |
---|---|---|---|---|
1 |
12 |
5 |
4 |
9 |
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
>> ma1_team_3_teamnumber Enter diameter of Tank 1: 12 Enter height of Tank 1: 5 Enter diameter of Tank 2: 4 Enter height of Tank 2: 9 The capacity of Tank 1 in U.S. gallons is:
tank1_capacity =
1.4939e+05
The capacity of Tank 2 is 29877 U.S. gallons. Tank 2 has a diameter of 13.1 ft and is 29.5 ft tall