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

MATLAB 2. 2. Volume of a cylindrical tank a a conical bottom with The figure bel

ID: 3678795 • Letter: M

Question

MATLAB

2. 2. Volume of a cylindrical tank a a conical bottom with The figure below shows a cylindrical tank with a conical bottom. Note that the radius of the tank is R. 2R Write a MATLAB function that computes the volume of the liquid in the tank as a function of R and d. The input should be scalar value for R but can be a vector value for d. ie. for a given radius we want the volume for a number of different values of depth, d. It should also return a value of Inf for the volume if any of the depth value is greater than 3R. Test the program with the following data.

Explanation / Answer

function ANS = twodotthirteen( R )
%TWODOTTHIRTEEN volume oc cylindrical tank with conical base
    maxDepth = 3*R;
    minDepth = 0;
    step = .1;
    depth = (minDepth:step:maxDepth);
    for i = 1:maxDepth/step + 1
        if (depth(i) <= R)
            V(i) = (pi * R^2*depth(i))/3;
        else
            V(i) = ((pi * R^3)/3)+(pi * R^2 * (depth(i)-R));
        end
    end
    plot(depth,V);
    ANS = horzcat(depth.',V.');
end


Command Window shows as following

>>twodotthirteen(1)    %radius =1

ans =


        0               0
   0.1000          0.1047
   0.2000          0.2054
   0.3000          0.3142
   0.4000          0.4159
   0.5000          0.5236
   0.6000          0.6283
   0.7000          0.7330
   0.8000          0.8378
   0.9000          0.9425
   1.0000          1.0472
   1.1000          1.3614
      '               '
      '               '
      '               '
   3.9000          7.3394

The following figure shows the Function: