clear all

% Plot concentration for zeroth order reaction A->B. At time t=0, 
% A_init=1M 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/16/2020

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

t1 = linspace(0,1/k,n);         % Time vector 1. Units are seconds.
t2 = linspace(1/k,2/k,n);       % Time vector 2 (for dashed line).

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

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

A_impossible = A_init - k*t2;   % Impossible negative concentration.
B_impossible = B_init + A_init - A_impossible; % Impossible at long times.


% create plot

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

figure(1); clf
plot(t1,A,'k',t1,B,'r',t2,A_impossible,'k--',t2,B_impossible,'r--','linewidth',pl_lw)
xlabel('time (s)','fontsize',la_fs)
ylabel('concentration (M)','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.2 1.2])
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])

