I need this code to start from 5 to 1. How can I do this?

7 views (last 30 days)
Hi I am doing a draining tank problem where the initial water height is 5 m and it drops to 1 m. Can someone help me have it plot starting from 5 and going down gradually to 1 m?
clc;clear all;close all;
pw=1000;%Density of water (kg/m^3)
P_atm=101;% Atmosphere pressure(kPa)
A_T=10;% Cross sectional area (m^2)
A2=0.001;% Opening area (m^2)
g=9.81; %Gravity (m/s^2)
H=6;% Height of tank (m)
z1=5;% Initial water height (m)
h1=5;
h2=1; %Water level final (m)
z2=1;% Final water height (m)
V2=sqrt(2*g*(z1-z2))
D_T=sqrt((4*A_T)/pi)
D2=sqrt((4*A2)/pi)
t_seconds=(((sqrt(h1))-(sqrt(h2)))/(sqrt(g/2)))*((D_T/D2)^2)
t_minutes=t_seconds/60
%Question B
h1b=[5 4 3 2 1];
h2b=1;
V2b=sqrt(2.*g.*(h1b-h2b))
m2b=pw.*V2b.*A2
tb_seconds=(((sqrt(h1b))-(sqrt(h2b)))./(sqrt(g/2)))*((D_T/D2)^2)
tb_minutes=tb_seconds./60
figure(1)
plot(tb_minutes,h1b)
xlabel('Time (minutes)');
ylabel('Liguid Level Height (meters)');
legend('Liquid level from intial to discharge','Location','northwest');
figure(2)
plot(tb_minutes,V2b)
xlabel('Time (minutes)');
ylabel('Velocity of orifice (meters)');
legend('Outlet Velocity from intial to discharge','Location','northwest');
figure(3)
plot(tb_minutes,m2b)
xlabel('Time (minutes)');
ylabel('Flow rate outlet(m/s)');
legend('Outlet flow rate from intial to discharge','Location','northwest');
%Question C
Pg=1000;%kPa
P2c=101;%Assume water discharges into atmosphere
h1c=[5 4 3 2 1];
h2c=1;
c=Pg.*A_T.*(h1c-h2c);
V2c=sqrt((((2.*((c/(h1c-h2c)*A_T))-P2c))./pw)+(2.*(h1c-h2c).*g))
m2c=pw.*V2c*A2
tc_seconds=(((sqrt(h1c))-(sqrt(h2c)))./(sqrt(g/2)))*((D_T/D2)^2)
tc_minutes=tc_seconds./60
figure(4)
plot(tc_minutes,Pg)
xlabel('Time (minutes)');
ylabel('Pressure P1 (kPa)');
legend('Change Pressure P_1 over time','Location','northwest');
figure(5)
plot(tc_minutes,h1c)
xlabel('Time (minutes)');
ylabel('Liguid Level Height (meters)');
legend('Liquid level from intial to discharge','Location','northwest');
figure(6)
plot(tc_minutes,V2c)
xlabel('Time (minutes)');
ylabel('Velocity of orifice (meters)');
legend('Discharge velocity over time V_2','Location','northwest');

Answers (1)

Walter Roberson
Walter Roberson on 11 Dec 2017
You have
h1b=[5 4 3 2 1];
h2b=1;
V2b=sqrt(2.*g.*(h1b-h2b))
m2b=pw.*V2b.*A2
tb_seconds=(((sqrt(h1b))-(sqrt(h2b)))./(sqrt(g/2)))*((D_T/D2)^2)
tb_minutes=tb_seconds./60
figure(1)
plot(tb_minutes,h1b)
This does use decreasing height, but your calculation for tb_seconds computes a lower time for a lower height, so tb_minutes decreases as h1b decreases. Then when you plot(tb_minutes,h1b) you are plotting decreasing minutes with decreasing height, which will have exactly the same appearance as if you had drawn with increasing minutes for increasing height.
I notice that you calculate V2b in terms of h1b, and you calculate m2b in terms of V2b, but you do not use m2b in calculating tb_seconds. This suggests you might have overlooked something in the calculation.
Do you want to use h1b as the current height? If so then you need to be accumulating times from the beginning of the dropping. Or do you want to use h1b as how far it has already dropped?
  1 Comment
Lakhvir Sandhar
Lakhvir Sandhar on 11 Dec 2017
So I guess the h1b and h1c are the heights of the water level dropping so they would probably be the current height on its way to meet h2b and h2c as its final height of 1 m.

Sign in to comment.

Categories

Find more on General Physics in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!