% Modified version of the MATLAB template file SolvIVDifI.m used to solve
% Example 1 of Supplemental Unit S5 of "A First Course on Kinetics and
% Reaction Engineering."
%
function [t_f,z] = S5_Example_1
    % Known quantities and constants (in consistent units)
    A = 0.1597;

    % Define the internal functions that will be needed
    
	% Function that evaluates the ODEs
    function dzdt = odeqns(t,z)
        dzdt = [
            -A*z(1)/(z(1) + z(2))
            0.5*A*z(1)/(z(1) + z(2))
        ];
    end % of internal function odeqns
        
    % Initial and final values
    t0 = 0.0;
    z0 = [
        0.103
        0.0
    ];
    tf = 1.0;
        
    % Solve the ODEs
    [t,zz] = ode45(@odeqns,[t0 tf],z0);

    % Return the values of the independent and dependent variables when the
    % integration stopping condition was satisfied
	last_value = length(t);
	t_f = t(last_value);
	z = zz(last_value,:);
	
    % calculate the percent change in z(1)
    pct_change = 100*(z(1)-z0(1))/z0(1)
    
end % of S5_Example_1.m
