Returning variables from ode45/15s method

4 views (last 30 days)
Charlie
Charlie on 19 Dec 2013
My Main code
%Partial Pressure and T profiel of hydrocarbon oxidation process %Represents steady-state, pseudo homogeneous system %Assume that O2 supply is unlimited.
clear
clc
global R dt dp qb Mm us H_r Cp pt pbo U Ta
%Physical parameters
R = 8314.5; %Gas constant [kJ/m^2*s]
L = 3; %Tube length [m]
dt = 2.54*10^-2; %Tube diameter [m]
dp = 3*10^-3; %Particle diameter [m]
qb = 1300; %Bulk density of catalyst [kg/m^3]
Mm = 29.48; %Mean molar mass [kg/kmole]
us = 1; %Fluid velocity [m/s]
H_r = 1285409; %Heat of reaction [kJ/kmole]
Cp = 0.992; %Specific heat [kJ/Kg*K]
pt = 1*10^5; %Total pressure [Pa]
pbo = 0.211*10^5; %Partial pressure of oxygen [Pa]
U = 0.096; %Overall heat transfer coefficient [kJ/m^2*s]
Ta = 352+273; %Ambient temperature [K]
pao = 0.015*10^5; %Artificial initial condition (can be varied)
%Initial Condition
po = pao;
To = Ta;
yo = [po To];
%ODE solver
[z,y] = ode15s('HC_oxidation_model', [0 L], yo);
subplot(2,1,1) plot(z,y(:,1)) title('Partial pressure profile along the tube for HC') xlabel('z [m]') ylabel('Partial Pressure [Pa]')
subplot(2,1,2) plot(z,y(:,2)) title('Temperature profile along the tube for HC') xlabel('z [m]') ylabel('Temperature [K]')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
And here's my model code
function dydz = HC_oxidation_model(z,y)
%Differential Equation Model for HC oxidation
global R dt dp qb Mm us H_r Cp pt pbo U Ta
pA = y(1);
T = y(2);
k = (10^-10)*exp(19.837 - 13636/T)/3600;
r = k*pbo*pA;
qg = (pt*Mm)/(R*T);
dTdz = (H_r*qb*r - 4*(U/dt)*(T-Ta)) / (us*qg*Cp);
dpdz = (pA/T)*dTdz - (R*T/us)*r*qb;
dydz = [dpdz; dTdz];
test = y(2);
disp(test)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
So as you can see in my model code, I declared a variable called "test" which is basically the
temperature profile. I know it's a little redundant in this case, since the ode method is
already solving for T = y(2). But, is there a way such that I can return the "test" variable in
a vector form? I tried including it as an output variable for my model, and on the ode solver
syntax, but that didn't seem to work. Typing in disp(test) obviously lets me see the variable
but it'd be nice if there's a way to return that variable in a nice column/row vector so I can
use it for further data manipulation.
Thanks~

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!