What am i doing wrong?
Afficher commentaires plus anciens
I am currently trying to solve the following equations to gain a plot of temperature and molar flowrates of A, B and C all against volume with a cross sectional area assumption of 1 dm^3.
my code and the data are as follows but i keep getting parse and input errors, can anyone help please?
function F = Q1a(V,Y)
%series rxns
Fa = Y(1);
Fb = Y(2);
Fc = Y(3);
T = Y(4);
%defining k1 (dm^3 / mol min) & k2 (dm^6 / mol^2 min)
R = 8.314462; %j / mol k
k1 = 50 * exp((8000/R)*(1/315 - 1./500));
k2 = 400 * exp((8000/R)*(1/310 - 1./500));
K3 = k1/k2;
%defining heat capacities
%all cps J / mol k
Cpa = 20;
Cpb = 80;
Cpc = 100;
Cpi = Cpa;
Cpcool = 10;
%change in cp
DCp1 = Cpb - (2*Cpa);
DCp2 = Cpc - (2*Cpb) - Cpa;
%Temperatures k
T0 = 500;
Ta = 523;
%Enthalpy of rxns J / mol A
DH1 = -25000 + (DCp1 * (T - T0));
DH2 = 350000 + (DCp2 * (T - T0));
CT0 = 0.399; %mol / dm3
FT0 = 5; %mol / min
Ua = 150; %J / dm3 min k
FT = Fa + Fb + Fc;
Ca = CT0 * ((Fa/FT)*(T0./T));
Cb = CT0 * ((Fb/FT)*(T0./T));
Cc = CT0 * ((Fc/FT)*(T0./T));
%Defining rates
ra = (k1*(Ca^2)) - (K3*Cb) + (k2*Ca*(Cb^2));
rb = (k2*Ca*(Cb^2)) + (K*(Cb)) - (k1*(Ca^2));
rc = k2*Ca*(Cb^2);
r1 = (k1*Ca^2) - (K3*Cb);
r2 = k2*Ca*Cb^2;
%Defining Differential equations
dFadV = -ra;
dFbdV = -rb;
dFcdV = rc;
dTdV = ((Ua * (Ta - T) - ((r1*DH1)) - (r2*DH2))) / ((Cpa*Fa) + (Cpb*Fb) + (Cpc*Fc));
F = [dFadV; dFbdV; dFcdV; dTdV];
end
%% plotting
clear all;
Vspan = [0 10];
Y0 = [5 0 0 300];
[V, Y] = ode45(@Q1a, Vspan, Y0)
subplot(2,1,1)
plot(V,Y(:,1), VY(:,2), VY(:,3))
legend('Fa', 'Fb', 'Fc');
ylabel('MolarFlowrates, mol/min')
xlabel('Volume, dm3')
subplot(2,1,2)
plot(V,Y(:,4))
Legend('Temperature'/ 'K');
ylabel('Temperature' / 'K');
xlabel('Volume dm^3');

4 commentaires
Walter Roberson
le 29 Déc 2020
Move
‰plotting
onwards into a different file than the function.
Or move the function definitions to the end of the one file
Chris Quinlan
le 29 Déc 2020
Modifié(e) : Chris Quinlan
le 29 Déc 2020
Walter Roberson
le 31 Déc 2020
rb = (k2*Ca*(Cb^2)) + (K*(Cb)) - (k1*(Ca^2));
uses K but K is not defined. Is k3 intended?
Once your temperature, Y(4), gets below 300, then the function oscillates rapidly, dropping to 0 quickly, and varying by +/- ten thousand-ish on trials with step size down around 1e-15. The system just cannot stabilize with negative temperature.
Chris Quinlan
le 31 Déc 2020
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!