function cdot = deriv02(tau,c)
%
% function deriv02(tau,c) supplies the ODE definitions
% needed by m-file ex02.m
% ex02 calls the standard MATLAB function ode45()
% and ode45() calls deriv02()
%
% c holds the dependent variables, concentrations
% in deriv02.m, c is a 2x1 array with two elements, c(1) and c(2)
% c(1) is dependent variable #1, conc of A
% c(2) is dependent variable #2, conc of B
% tau is the independent variable, space time
% cdot is a 2x1 array that receives the values of the derivatives
% cdot(1) = dc1dtau = dc(1)/dtau, cdot(2) = dc2dtau = dc(2)/dtau
% SPECIAL NOTE: In many cases, your dependent variables will have different
% names. For example, concentration of A and temperature. In such a
% case, pick a general name such as "y" for the matrix that holds the dependent
% variables. Then, in the "deriv" file, the first element y(1) would hold
% the concentration values, and the second element y(2) would hold the
% temperature values. The "ydot" matrix would hold the derivatives
% in the same order. Write some comments defining the relationships
% and use these definitions in the main m-file and the "deriv" m-file.
% declare "global" variables shared with file "ex02.m"
% their values are assigned in file "ex02.m"
global k1 k2
% c(1) and c(2) are each one element arrays so .* not needed below
% calculate derivatives
% dc1dtau = dc(1)/dtau, dc2dtau = dc(2)/dtau
dc1dtau = - k1 * c(1);
dc2dtau = k1 * c(1) - k2 * c(2);
% need to combine values into one column vector
cdot = [dc1dtau; dc2dtau];
% cdot column vector is returned by this function to the calling routine
% end of function