clear all

% Plot concentration for first-order reaction A->B. At time t=0, 
% A_init=4mM and B_init=0. 
%
% Executes properly on MATLAB version 9.4.0.813654 (R2018a).
% Executes mostly properly on OCTAVE version 4.2.1.
% Joshua C. Vaughan 4/17/2020

n = 2^8;                        % Number of samples along time axis.
k = 0.4;                        % Rate cosntant. Units are M/second.

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


A_init = 0.004;                     % Initial concentration of A. Units are molar.
B_init = 0;

A = A_init*exp(-k*t);          % Integrated rate law for A(t).
B = B_init + A_init - A;        % B(t)


% create plot

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

fac = 1000; % convert units from molar to milimolar

figure(1); clf
plot(t,A*fac,'k',t,B*fac,'r','linewidth',pl_lw)
xlabel('time (s)','fontsize',la_fs)
ylabel('concentration (mM)','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)
%xlim([0 1.2*(1/k)])
ylim([0 1.1*max(A)*fac])
h = legend('[A(t)]','[B(t)]');
set(h,'box','off')
set(h,'fontsize',20)
set(h,'position',[0.7122    0.6237    0.1817    0.1410])

