% example of integrating single ODE with matlab
% A -> B essentially irreversible rxn in an isothermal, isobaric PFR
% x is the dependent variable, fractional conversion of "A"
% tau is the independent variable, space time
% declare "global" variables whose values are shared with file "deriv01.m"
global k
k = 1; % set rate constant used in "deriv01.m"
tauSpan = [1 10]; % set span of tau
x0 = [0]; % set initial conversion
% call ode45 integrator
% 'deriv01' is defined in the file "deriv01.m"
% this is a user-written "m" file containing the derivative equation
[tau,x] = ode45('deriv01', tauSpan, x0);
% all the integration is finished now, so plot and save results
plot(tau,x)
title('example of integrating one ODE')
xlabel('tau (space time)')
ylabel('x (fractional conversion)')
info = 'press any key to continue'
pause
% put tau and x into one array so disk file
% will be in correct format for loading into graphing program
u = [tau, x];
info = 'Saving data tab-delimited text file "data01.temp"'
% col 1 = tau, col 2 = fractional conversion x.
% IMPORT as Text file with Delimeter = Tab
save data01.temp u -ascii -tabs
info = '*** ex01 finished ***'