In: Computer Science
Part A: Write a MATLAB script to find the volume of the cylinder in gallons, as well as the tank dimensions in feet. Assume that the initial measurements are 7 meters in diameter and 11 meters tall. Display your final answers to the screen using disp and a statement without a semicolon, e.g. write the following into your script disp(‘The capacity in U.S. gallons is:’), capacity, where capacity is a variable that you defined in preceding calculations.
Part B: In the same MATLAB script, perform the same calculations for a second tank that is 3 meters in diameter and 8 meters tall. This time, use fprintf to achieve the following output (no decimals for the capacity and one decimal for the dimensions): The capacity is X gallons. The tank has a diameter of X.X ft and is X.X ft tall.
clc;clear all
%%Part-A
D=input('Enter the diameter of tank in metre: '); %User enters
diameter
H=input('\nEnter the height of tank in metre: '); %User enters
height
V=0.25*pi*D^2*H; %Finds volume in m^3
Vgal=264*V; %Converting to gallon
Dfeet=3.281*D; %Converting m to feet for diameter
Hfeet=3.281*H; %Converting m to feet for height
X=['The capacity in US gallons is: ',num2str(Vgal)]; %For printing
using disp command
disp(X)
Y=['The diameter is: ',num2str(Dfeet),' feet and height is
',num2str(Hfeet),' feet']; %Prints D and H
disp(Y)
clc;clear all
%%Part-B
format short
format compact
D=input('Enter the diameter of tank in metre: '); %User enters
diameter
H=input('\nEnter the height of tank in metre: '); %User enters
height
V=0.25*pi*D^2*H; %Finds volume in m^3
Vgal=264*V; %Converting to gallon
Dfeet=3.281*D; %Converting m to feet for diameter
Hfeet=3.281*H; %Converting m to feet for height
%%Using fprintf command for printing as per specified
fprintf('\nThe capicity is %d gallons. The tank has a diameter of
%.1f ft and is %.1f ft tall',Vgal,Dfeet,Hfeet)
Please upvote :)