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

Click For Summary
SUMMARY

The discussion focuses on solving coupled ordinary differential equations (ODEs) using MATLAB's ode45 function for a reactor temperature problem. The user encountered issues with NaN outputs when attempting to compute concentrations and temperature. Key parameters include a reactor volume of 150 L, a reaction rate constant of 0.02 L/mol*min, and an initial temperature of 300 K. The solution was found by correcting the function definition of the ODE to exclude the control input parameter, allowing for successful computation of the desired outputs.

PREREQUISITES
  • Understanding of coupled ordinary differential equations (ODEs)
  • Familiarity with MATLAB programming and syntax
  • Knowledge of chemical reaction kinetics and reactor design
  • Experience with numerical methods, specifically MATLAB's ode45 function
NEXT STEPS
  • Review MATLAB documentation on ode45 for advanced usage and troubleshooting
  • Study the formulation of coupled ODEs in chemical engineering contexts
  • Learn about matrix representations of ODE systems for improved problem-solving
  • Explore techniques for handling NaN outputs in numerical simulations
USEFUL FOR

Students and professionals in chemical engineering, particularly those working with reactor design and numerical simulations of reaction kinetics using MATLAB.

gfd43tg
Gold Member
Messages
948
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
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 6 ·
Replies
6
Views
7K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 1 ·
Replies
1
Views
892
  • · Replies 4 ·
Replies
4
Views
2K
Replies
3
Views
5K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 1 ·
Replies
1
Views
14K
  • · Replies 6 ·
Replies
6
Views
2K
Replies
1
Views
3K