When I attempt to run this code, it doesnt stop running. It will only stop when I pause it. Would appreciate any help as to how to fix this?
1 view (last 30 days)
Show older comments
function f = PBR1(W,Y)
%series reactions Y is the concentrations of species and V PFR volume
X= Y(1);
T= Y(2);
Ta=Y(3);
P= Y(4);
%explicit equation
deltaHrx1=-20000; %cal.mol-1
Cao=2;%mol.dm-3
To=300;%K
Po=14.9652;%Pa
R=1.986; %cal.K-1.mol-1;
Fao=0.0278; %mol.s-1
Fbo=0; %mol.s-1
Fio=0.0556; %mol.s-1
Cpa=150; %cal.mol-1.K-1
Cpb=150;%cal.mol-1.K-1
Cpi=20;%cal.mol-1.K-1
Cpco=20;%cal.mol-1.K-1
mco=0.833333;%mol.s-1
Ua=150;%cal.dm-3.s-1.K-1
rho=1.2;%kg.dm-3
alpha=0.2;%kg-1
Ca=Cao*((1-X)*(P/Po)*(To./T));
Cb=Cao*((X)*(P/Po)*(To./T));
k=0.00167;%s-1
keq=1000;
E=10000;%cal.mol-1
k1=k*exp((E/R)*(1/300-1./T));%cal.mol-1.min-1
kc=keq*exp((deltaHrx1/R)*(1/305-1./T)); % dcal/mol.s
Tao=300;%K
ra=k1*(Ca-(Cb/kc));
%differential equations
dXdW=-ra/Fao;
dTdW=(((Ua/rho)*(Ta-T))+((-deltaHrx1)*(-ra)))/(Cpa*Fao+Cpb*Fbo+Cpi*Fio);
dTadW=-((Ua*rho)*((Ta-T)/(mco*Cpco)));
dPdW=-((alpha/2)*(Po)*(Po/P)*(T/To));
f=[dXdW; dTdW; dTadW; dPdW];
end
clc
Wspan=[0 48];
yo=[0 300 300 14.9652];
[W, y]=ode45(@PBR1, Wspan, yo);
subplot(2,1,1)
plot(W,y(:,1));
legend('X');
ylabel('Conversion');
xlabel('Weight of Catalyst,Kg');
subplot(2,1,2)
plot(W,y(:,2),W,y(:,3));
legend ('T','Ta');
ylabel( 'Temperature (K)');
xlabel('Weight of Catalyst,Kg');
subplot(2,1,3)
plot(W,y(:,4));
legend ('P');
ylabel( 'Pressure (Pa)');
xlabel('Weight of Catalyst,Kg');
0 Comments
Answers (2)
Alan Stevens
on 4 Jan 2021
Your pressure goes negative just after a catalyst weight of 5 kg. Should it do this? Perhaps your equations should be double-checked.
You also have subplot(2,1,x), but want three subplots, so these should be subplot(3,1,x).
I suggest using ode15s instead of ode45 here (though this won't get you much past 5 kg!).
0 Comments
Bjorn Gustavsson
on 4 Jan 2021
If your odes should have positive solutions (haven't checked them to be able to judge this), and they happen to become negative for numerical reasons, then you can explicitly tell some of the odeNN functions to give you a non-negative solution using the odeset function to generate an options structure:
opts = odeset('NonNegative',1);
See the documentation at: non-negative ode solution
HTH
0 Comments
See Also
Categories
Find more on Ordinary Differential Equations 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!