im having trouble finding the right values for this codes

9 views (last 30 days)
Christella Bañaga
Christella Bañaga on 27 Oct 2021
% A 1500 gallon tank initially contains 600 gallons of water with 5 lbs of salt dissolved in it.
% Water enters the tank at a rate of 9 gal/hr and the water entering the tank has a salt concentration
% of 1/5*(1+cos(t)) lbs/gal. If a well mixed solution leaves the tank at a rate of 6 gal/hr, how much salt is in the
% tank when it overflows?
%Setup the variables t and X(t) as the function of Salt in the tank over a period of time t.
%Find also the derivative of X(t) and set as dX
syms t X(t)
dX = diff(X,t)
%Initial Conditions
Vo = 600
Vmax = 1500
cond1 = X(0)==5
%Flow Rates
cin = (1/5)*(1+cos(t))
qin = 9
qo = 6
V(t) = symfun(600+3*t,t)
co = X(t)/V
%Set the differential equation model as eqn1;
eqn1 = dX+((2*X)/(200+t))==((9/5)*(1+cos(t)))
%Find Xsoln by solving the initial value problem eqn1 using cond1
Xsoln = dsolve(eqn1,cond1)
x = solve(eqn1);
%Find the time when the tank will be full (tfull), that is when will the Volume reach Vmax
tfull = sym(300)
%Use the subs command to substitute t=tfull in the modelled equation. Save answer as XFull
XFull = subs(tfull,300)
% Plot the equation: Use the Title=Mixture of Salt Water, XValue=Time (in Hours), YValue=Amount of Salt (lbs)
Title = "Mixture of Salt Water"
XValue = "Time (in Hours)"
YValue = "Amount of Salt (lbs)"
%Use the domain (0, tfull+5) with 0.2 gaps from each point
hold on;
hold off;
% Plot the equation: Use the Title=Mixture of Salt Water, XValue=Time (in Hours), YValue=Amount of Salt (lbs)

Answers (1)

Alan Stevens
Alan Stevens on 27 Oct 2021
This should allow you to find the right values, though it might not be quite the way you were tasked to do it!
%Initial Conditions
V0 = 600; % gal
Vmax = 1500; % gal
X0 = 5; % lbs salt
tfull = (Vmax - V0)/3; % hrs
tspan = [0 tfull];
[t, X] = ode45(@fn, tspan, X0);
disp(['Amount of salt in tank when it overflows = ' num2str(X(end)) ' lbs'])
Amount of salt in tank when it overflows = 276.2121 lbs
% Plot the equation
Title = "Mixture of Salt Water";
XValue = "Time (in Hours)";
YValue = "Amount of Salt (lbs)";
plot(t,X,'b'), grid
% Amount of salt function
function dXdt = fn(t, X)
V = 600 + 3*t; % gal
dVindt = 9; % gal/hr
dVoutdt = 6; % gal/hr
dXindt = dVindt*(1/5)*(1 + cos(t)); % lbs/hr
dXoutdt = dVoutdt*X/V; % lbs/hr
dXdt = dXindt - dXoutdt; % lbs/hr
Christella Bañaga
Christella Bañaga on 29 Oct 2021
the program you provided works but not on the codes that im dealing with so that's why it does not work

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!