MATLAB: Setting up ODE in Matlab for ODE 45 solver

coupleddifferential equationskineticsodeode45

Hi, I am having difficulty setting this problem up for the ODE45 solver. It is a kinetics equation, relating R (rate constants as a function of concentrations C), T (Temperature) and h (heat of formation) all of which vary with distance x. There are 3 species that take part in the reaction.
How do I formulate the function that calculates all these parameters to call in the ODE45 solver ( something like dTdx = …. ) How to plot x,T and x,C (what would be the correct syntax to plot these). Any help with a pseudo code will be greatly appreciated.

Best Answer

function dydx = hw2_5(x,y)
C(1) = y(1);
C(2) = y(2);
C(3) = y(3);
T = y(4);
% Constants
A = 2.2e10;
Ea = 130000;
Ru = 8.3145;
rho=1.3;
cp=1200;
u=1.5;
% Rate Constants and heat of formation
h(1)=-110530;
h(2)=0;
h(3)=-393520;
R(1) = -A * (exp(-Ea /(Ru*T))) * C(1) * sqrt(C(2));
R(2) = 0.5 * R(1);
R(3) = -R(1);
dTdx=-(R(1)*h(1)+R(2)*h(2)+R(3)*h(3))/(cp*rho*u);
dydx = [R(1);R(2);R(3);dTdx]
Best wishes
Torsten.
Related Question