Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB HELP A fuel tank is made of a half cylinder of radius r and length L as s

ID: 1766386 • Letter: M

Question

MATLAB HELP

A fuel tank is made of a half cylinder of radius r and length L as shown in Figure. The amount of fuel in gallons as a function of h is given by cos -- fuel 231 (2 pts) Write a script file HW4P3.m that prompts the user to enter the tank radius and length in inches, r and L, respectively. You can use separate input command for every variable (2 pts) The code must create a vector for h ranging from 0 to r with 21 elements. (4 pts) Then the code must calculate the corresponding volume of fuel using equation (1) and round it to the nearest tenth of a gallon. (2 pts) The code then must create a 2 × 21 array called hv where the first row is the values of h (in inches) and the second row is the associated values of the volume of fuel in the tank (in gallons) (9 pts) Run your code for the following cases: a. r 10 in and L = 20 in b, r = 20 in and L = 30 in C. r = 30 in and L = 40 in Hint: in stands for inches. When your file for case (a) is run the display in the command window must be similar to Please enter the radius of the tank in inches:I Please enter the length of the tank in inches: I For a half cylindrical fuel tank of radius 10.00 in and length = 20.00 in, the volume of fuel in the tank as a function of height is: Height Volume [inch] [Gallon] 0.00 0.50 1.00 1.50 2.00 0.00 0.20 0.50 0.90 Use fprintf with format 5.2f for all numbers in this problem. (2 pts) Find the transpose of hV and save it to an ascii format data file with the name HW4P1.dat that can be read on other platforms than MATLAB

Explanation / Answer

% Copy and Paste it matlab
clc;clear; % To clear all the previous working data

r=input('Please enter the radius of the tank in inches '); % To take r value
l=input('Please enter the length of the tank in inches '); % To take L value
h=0:(r/20):r; % Creating h vector 0 to r with 21 elements
v=(l/231)*(r^2*acos((r-h)/r)-((r-h).*sqrt(2*r.*h-h.^2))); % Calculating v value
roundn = @(x,n) round(x*10^n)./10^n; % Creating a function to roundoff upto n decimals
vn=roundn(v,1); % Rounding of to nearest 10th of gallon

hv=[h ;vn]'; % Creating array to store height and volume
fprintf(' For a half Cylindrical fule tank of radius %d in and lenght %d in ',r,l);
fprintf('The volume of fuel in the tank as a function of height is : ');
hv

save HW4P1.dat hv -ascii %saving results to ascii format