In: Mechanical Engineering
This is the Matlab practice so needs Matlab code
2. Numerical Integration
Consider an industrial tank in the shape of an inverted cone. The
radius of the tank at the top rim is 3 m, and the total height of
the tank is 4 m.
The volume of the tank in m3 is given by: V = (1/3) R2 H.
The volume of liquid in the tank when filled to a height h measured
from the bottom vertex is:
V = (1/3)pi* (R/H)2 h3
The Lab will consist of a single script, divided in two parts. In
each part, the filling schedule will be different. A filling
schedule is a function that provides flow rate, in m3 / h, as a
function of time.
In Part I, your script will calculate the level of the liquid, h,
after a two-hour filling schedule is completed. The filling
schedule for Part I, Schedule I, is as follows:
During the first 30 minutes, the flow rate will increase linearly
from zero to 10 m3 / h
During the following 60 minutes, the flow rate will stay constant
at 10 m3 / h
During the last 30 minutes, the flow rate will decrease linearly
from 10 m3 / h down to zero
In Part II, your script will calculate the time it takes to
completely fill the tank with a different filling schedule,
Schedule II, given by the equation:
Flow Rate (m3 / h) = 10 (1 - e-2t ) m3 / h
where t is time in hours, and the exponent, 2t, is
dimensionless
Part I:
The volume of liquid calculated in Part I, from which the height of
the liquid in the tank will be calculated, should be obtained by
using the built-in function to integrate polynomials, polyint(
)
Part I generates a single output to the console: "The height of the
liquid after Schedule I is ____ meters."
Part II:
In Part II, your script first defines Schedule II as an anonymous
function
In Part II your script calculates the volume at a given time by
integrating Schedule II using the built-in function quad( )
For Option A, it is acceptable to use a loop to find the time at
which the tank gets completely full. If you will use an iterative
approach, check the tank volume in 0.01 hour steps
Part II generates a single output to the console: "The time
required to fill up the tank with Schedule II is ____ hours."
MATLAB CODE:
clc;
clear;
R=3; %radius of tank
H=4; %tank height
% part I
q1=[20 0]; %polynomial representation for time
0-30min
q2=[20]; %polynomial representation
for time 30-90min
q3=[-20 0]; %polynomial representation for time
90-120min
lm_1=[0 0.5]; %time for first schedule in hours
lm_2=[0.5 1.5]; %time for second schedule in hours
lm_3=[1.5 2]; %time for third schedule in hours
P_1=polyint(q1);
P_2=polyint(q2);
P_3=polyint(q3);
V_1=(polyval(P_1,lm_1(2))-polyval(P_1,lm_1(1)))+(polyval(P_2,lm_2(2))-polyval(P_2,lm_2(1)))+(polyval(P_3,lm_3(2))-polyval(P_3,lm_3(1)));
h=(3*V_1/(pi*(R/H)^2))^(1/3);
fprintf('The height of the liquid after Schedule I is %.3f
meters\n\n\n',h);
% part II
V=1/3*pi*R^2*H; %total volume of tank
er=1; %initial error for starting loop
a=0; %initial limit
b=0.01; %final limit for iteration 1
Q =@(t) 10*(1-exp(-2*t)); %flow rate function
it=0; %iteration count
V_t=0; %volume initial
while er>0.1;
V_t=V_t+quad(Q,a,b); %volume
filled
er=abs(V-V_t); %error
t=b; %new
time
a=b; %new
limits
b=b+0.01; %new limits
it=it+1; %iteration number
end
fprintf('The time required to fill up the tank with Schedule II is
%.3f hours.\n',t);
SAMPLE OUTPUT: