im having trouble finding the right values for this codes

8 visualizaciones (últimos 30 días)
Christella Bañaga
Christella Bañaga el 27 de Oct. de 2021
Comentada: Christella Bañaga el 29 de Oct. de 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
x=0:0.1:tfull+5;
y=subs(Xsoln,t,x)
plot(x,y,'b--');
hold on;
title(Title);
xlabel(XValue);
ylabel(YValue);
plot(0,subs(Xsoln,t,0),'r*');
plot(tfull,subs(Xsoln,t,0),'r*');
hold off;
% Plot the equation: Use the Title=Mixture of Salt Water, XValue=Time (in Hours), YValue=Amount of Salt (lbs)

Respuestas (1)

Alan Stevens
Alan Stevens el 27 de Oct. de 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
title(Title);
xlabel(XValue);
ylabel(YValue);
% 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
end
  3 comentarios
Alan Stevens
Alan Stevens el 28 de Oct. de 2021
In what sense do you think it doesn't work?
Clearly the program works, though I used Matlab's in-built ode45 solver to do it, rather than the method you seem to have been asked to use. This should enable you to check if your result is close to the ode45 result.
Christella Bañaga
Christella Bañaga el 29 de Oct. de 2021
the program you provided works but not on the codes that im dealing with so that's why it does not work

Iniciar sesión para comentar.

Categorías

Más información sobre First Year Engineering en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by