clear all

% Plot concentrations for the multi-step first-order sequential chemical 
% reaction A->B->C where k1 and k2 are not equal. At time t=0, 
% A1_init_conc=1M and all other species have zero concentration. 
%
% Executes properly on MATLAB version 9.4.0.813654 (R2018a).
% Executes mostly properly on OCTAVE version 4.2.1.
% Joshua C. Vaughan 4/25/2020

n = 2^8;                        % Number of samples along time axis.
k1 = 1.5;                       % Rate cosntant for first reaction. Units are 1/second.
k2 = 0.3;                       % Rate constant for second reaciton. Units are 1/second.

t = linspace(0,10,n);           % Time vector. Units are seconds.

A_init_conc = 1;                    % Initial concentration of A1. Units are molar.

A = A_init_conc*exp(-k1*t);
B = A_init_conc*k1*(exp(-k1*t)-exp(-k2*t))/(k2-k1);
C = A_init_conc*((k1*exp(-k2*t))/(k2-k1) - (k2*exp(-k1*t))/(k2-k1) + 1);


% create plot

ax_lw = 2;
pl_lw = 2;
ax_fs = 24;
la_fs = 24;
fontname = 'Arial';

figure(1); clf
plot(t,A,'k',t,B,'r',t,C,'g','linewidth',pl_lw)
xlabel('time (s)','fontsize',la_fs)
ylabel('concentration [arb.]','fontsize',la_fs)
set(gca,'ytick',[0 1])
set(gcf,'color',[1 1 1])
set(gca,'linewidth',ax_lw)
set(gca,'fontsize',ax_fs)
set(gca,'tickdir','out')
set(gca,'fontname',fontname)
h = legend('[A({\itt})]','[B({\itt})]','[C({\itt})]');
set(h,'box','off')
set(h,'fontsize',24)
set(h,'position',[0.6639    0.5647    0.2050    0.2320])
set(gca,'LooseInset',get(gca,'TightInset'));