ODE 45 with coupled ODE's in a matrix, reactor temp.

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 2K views
gfd43tg
Gold Member
Messages
949
Reaction score
48

Homework Statement


My question is regarding part (e), I just gave all the questions for reference.
upload_2015-9-9_17-47-26.png


Homework Equations

The Attempt at a Solution


These are the coupled equations I should solve (from part d)
upload_2015-9-9_17-50-15.png

My issue is using ode45 to get ##C_{A}(t)##, ##C_{P}(t)##, and ##T(t)##. Here is my m-file

Code:
function G = parte(t,x,u)

V = 150; % L
k = 0.02; % L/mol*min
beta = 0.15; % kJ L^.5 / mol^.5 min
DeltaH = -15; % kJ/mol A
rho = 4.2; % kg/L
cp = 1.2; % kJ/kg K

u = zeros(3,1);
u(1) = 1.4; % L/min
u(2) = 300; % K
u(3) = 40; % mol/LA = [-u(1)/V, u(1)*DeltaH/(rho*V*cp), beta/(2*rho*V*cp)*x(3)^(-0.5);
  0, -(u(1)/V) -2*k*x(2), 0;
  0, 2*k*x(2), -u(1)/V];

B = [(u(2)-x(1))/V + (x(2)-u(3))*DeltaH/(rho*V*cp), u(1)/V, -u(1)*DeltaH/(rho*V*cp);
  (u(3)-x(2))/V, 0, u(1)/V;
  -x(3)/V, 0, 0];

G = A*x + B*u;

end

Then I run it on my script
Code:
Ti = 300; % K
CAi = 40; % mol/L
CPi = 0; % mol/L
[T4,Y4] = ode45(@parte,[0 10],[Ti CAi CPi]);
subplot(1,2,1)
plot(T4,[Y4(:,2),Y4(:,3)])
xlabel('time (minutes)')
ylabel('Concentration (lb mol/ft^{3})')
legend('A','P','location','best')
title('Concentration vs. time')

And here is my output
Code:
[T4,Y4]

ans =

  0  300.0000  40.0000  0
  0.2500  NaN  NaN  NaN
  0.5000  NaN  NaN  NaN
  0.7500  NaN  NaN  NaN
  1.0000  NaN  NaN  NaN
  1.2500  NaN  NaN  NaN
  1.5000  NaN  NaN  NaN
  1.7500  NaN  NaN  NaN
  2.0000  NaN  NaN  NaN
  2.2500  NaN  NaN  NaN
  2.5000  NaN  NaN  NaN
  2.7500  NaN  NaN  NaN
  3.0000  NaN  NaN  NaN
  3.2500  NaN  NaN  NaN
  3.5000  NaN  NaN  NaN
  3.7500  NaN  NaN  NaN
  4.0000  NaN  NaN  NaN
  4.2500  NaN  NaN  NaN
  4.5000  NaN  NaN  NaN
  4.7500  NaN  NaN  NaN
  5.0000  NaN  NaN  NaN
  5.2500  NaN  NaN  NaN
  5.5000  NaN  NaN  NaN
  5.7500  NaN  NaN  NaN
  6.0000  NaN  NaN  NaN
  6.2500  NaN  NaN  NaN
  6.5000  NaN  NaN  NaN
  6.7500  NaN  NaN  NaN
  7.0000  NaN  NaN  NaN
  7.2500  NaN  NaN  NaN
  7.5000  NaN  NaN  NaN
  7.7500  NaN  NaN  NaN
  8.0000  NaN  NaN  NaN
  8.2500  NaN  NaN  NaN
  8.5000  NaN  NaN  NaN
  8.7500  NaN  NaN  NaN
  9.0000  NaN  NaN  NaN
  9.2500  NaN  NaN  NaN
  9.5000  NaN  NaN  NaN
  9.7500  NaN  NaN  NaN
  10.0000  NaN  NaN  NaN

I am not sure how to do this thing with the matrix format. I thought I set up my equations correctly, but can't figure out why it won't output correctly. I should note that the ##\sqrt {C_{P}}## is the concentration of P, whereas ##c_{p}## is a constant, in case that is confusing to anyone.
 
Last edited:
Physics news on Phys.org
There is a problem with your definition of the ODE function:
Matlab:
function G = parte(t,x,u)
It has to be of the form
Matlab:
function G = parte(t,x)
 
I decided to solve these explicitly rather than try the matrix formulation, so now I got it