Water Tank input that changes based on volume.

조회 수: 5 (최근 30일)
Karl Nilsson
Karl Nilsson 2020년 3월 12일
댓글: Karl Nilsson 2020년 3월 12일
Need to plot the volume of water and concentration of pollutant in a tank of water. Initial inflow is 1.25 m^3/s, and outflow is 1.1. When the tank's volume reaches 200 m^3, the inflow is 0, and returns to 1.25 when the volume drops to 150. How can inflow (Qin) be changed to 0 at V=200, and then reset at V=150? if statement?
Here is code for a prior part to the project that assumes a constant rate of fill:
V0 = 50; %initial volume (m^3)
c0 = 0; %initial concentration
Qin = 1.25 * 60; %inflow (m^3/hour)
Qout = 1.1 * 60; %outflow (m^3/hour)
cin = 100; %pollutant concentration (mg/L)
t_final = 50; %hours
dt = 0.5; %time step
T = [dt:0.5:50];
t = 0;
%
k = 0;
%
%Initialize Loop Variables
cold = c0;
vold = V0;
for n = [1 : (t_final/dt)];
t = t + dt;
k = 0;
alpha = (Qin / (vold + (Qin - Qout) * t)) + k;
beta = (Qin*cin)/(vold+(Qin - Qout) * t);
c(n) = cold - dt * alpha * cold + dt * beta;
V(n) = vold + (Qin - Qout) * dt;
cold = c(n);
vold = V(n);
end
yyaxis left
plot(T,V)
ylabel('Volume (m^3)')
xlabel('Time (hours)')
yyaxis right
plot(T,c)
ylabel('Concentration (mg/L)')
disp(' t V c')
format compact
disp([T' V' c'])
more(10)

채택된 답변

Subhamoy Saha
Subhamoy Saha 2020년 3월 12일
Please check with the following
clear, clc
V0 = 50; %initial volume (m^3)
c0 = 0; %initial concentration
Qin = 1.25 * 60; %inflow (m^3/hour)
Qout = 1.1 * 60; %outflow (m^3/hour)
cin = 100; %pollutant concentration (mg/L)
t_final = 50; %hours
dt = 0.5; %time step
T = [dt:0.5:50];
t = 0;
%
k = 0;
%
%Initialize Loop Variables
cold = c0;
vold = V0;
inflow=1; % inflow status variable
for n = [1 : (t_final/dt)]
t = t + dt;
k = 0;
if vold>=200 || inflow==0
inflow=0; % say inflow stopped
if vold<=150
inflow=1; % say inflow start
end
end
if inflow==0
Qin=0;
else
Qin=1.25 *60;
end
alpha = (Qin / (vold + (Qin - Qout) * t)) + k;
beta = (Qin*cin)/(vold+(Qin - Qout) * t);
c(n) = cold - dt * alpha * cold + dt * beta;
V(n) = vold + (Qin - Qout) * dt;
cold = c(n);
vold = V(n);
end
yyaxis left
plot(T,V)
ylabel('Volume (m^3)')
xlabel('Time (hours)')
yyaxis right
plot(T,c)
ylabel('Concentration (mg/L)')
disp('      t        V           c')
format compact
disp([T' V' c'])
more(10)
  댓글 수: 1
Karl Nilsson
Karl Nilsson 2020년 3월 12일
Thanks. I figured it out eventually but this is much more efficient.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by