Chemical Forums
Specialty Chemistry Forums => Chemical Engineering Forum => Topic started by: limonade on April 09, 2014, 11:36:45 PM
-
Hi there.
I am trying to use MATLAB to make a plot of PA vs time for the problem ( see picture #1)
I am able to get a component balance in terms of conversion, but when I integrate and use MATLAB to plot the conversion vs time I get the result = infinity for conversion. I do not know what is going wrong with my code.
I have attached the problem statement, my work on how I arrived at the equations, and my MATLAB code.
I am really really stuck here and would appreciate any help...
The code is here
clear all
clc
k = 1*10^-3;
KA = 10;
W = 0.1;
T = 400;
P = 100;
yA0 = 0.5;
yB0 = 0.5;
NA0 = .5 % Assuming a basis of 1 mol to start
Ptot = 100;
PA0 = 50;
V = 100,000; %cm3
R = 8.314*10^3 %units cm3 kPA K-1mol-1
i = 1; % initial array index
x(i) = 0; % dimensionless, initial conversion
t(i) = 0; % s, initial time
dt = 0.5; % s, step size
trxn = 5000; % s, final time
while t(i) <= trxn
dxdt = W*k*((PA0*(1-x)).^2)/(1+KA*(PA0*(1-x))*(PA0*V/R*T));
x(i+1) = x(i) + dxdt * dt
t(i+1) = t(i) + dt;
i = i+1; % increment array index
end
plot(t,x)
tt = sprintf('Conversion vs. time, X is %4.4f at trxn = %4.2f', max(x),trxn)
title(tt)
ylabel('X'), xlabel('time (s)')
axis([0 ceil(max(t)) 0 1])
max(x)
-
The "correct answer"/ resulting graph of partial pressure of A vs time should end up looking like this:
I just wanted to make sure that my conversion vs time graph comes out okay...
then I was going to make a while loop or something with an equation for pA in terms of Xa to get the graph asked in the problem statement.
-
There appears to be a discrepancty in the denominator of your dx/dt expression. Your code has
(1+KA*(PA0*(1-x))*(PA0*V/R*T))
while your manuscript has
((1+KA*PA0*(1-x))*(PA0*V/R*T))
Be careful with those brackets!
-
I double checked with the brackets, and it still is not coming out properly.
-
Many programs will interpret the "T" in that expression to be in the numerator of the latter part of the expression, that is, PAO*V*T/R.
Therefore, I suggest making sure you have a set of brackets around R and T uniquely.
I.e., something like:
dxdt = W*k*((PA0*(1-x)).^2)/((1+KA*PA0*(1-x))*(PA0*V/(R*T)));
This has still got some superfluous brackets in it, but it's ok I think. I assume all other syntax is correct - not sure what the . is for.
-
Have you tried with a smaller step size?
-
Thank you all very much for your replies. I figured it out.
For the volume, I put V = 100,000 cm3
It turns out that my MATLAB program interprets , as decimal points.
So.... 100,000 is read as 100.000
*sigh* terrible thing to spend so much time on it and not get the correct answer because of that
But now it works
Thanks again
-
You might fiind it worth creating some intermediate variables to make the algebra easier. For example
Y = PA0*V/(R*T)
Z = PA0*(1-x)
Then dx/dt = W*k*Z^2/((1+KA*Z)*Y)
Much less chance of accidental typos.