im having trouble finding the right values for this codes
조회 수: 2 (최근 30일)
이전 댓글 표시
% 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)
답변 (1개)
Alan Stevens
2021년 10월 27일
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'])
% 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
Alan Stevens
2021년 10월 28일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 First Year Engineering에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!