Figure 3.3:

Gibbs energy G versus reaction extent \varepsilon '.

Code for Figure 3.3

Text of the GNU GPL.

main.m


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
% Copyright (C) 2001, James B. Rawlings and John G. Ekerdt
%
% This program is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License as
% published by the Free Software Foundation; either version 2, or (at
% your option) any later version.
%
% This program is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
% General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; see the file COPYING.  If not, write to
% the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
% MA 02111-1307, USA.

K = 108;
P = 2.5;

xlogx = @(x) x.*log(x + eps(x)); % Makes sure 0*log(0) == 0.
G = @(x) -x*log(K) + (1 - x)*log(P) + xlogx(x) + ...
    2*xlogx(0.5 - x) - xlogx(1 - x);

npts = 100;
xcoarse = linspace(0, 0.5, npts)';
Gcoarse = G(xcoarse);

xfine = linspace(0.45, 0.5, npts)';
Gfine = G(xfine);

data = struct();
data.coarse = [xcoarse, Gcoarse];
data.fine = [xfine, Gfine];
Gmin = min(Gfine) - 0.025;
Gmax = max(Gfine) + 0.025;
data.box = [xfine([1; end; end; 1; 1]), [Gmin; Gmin; Gmax; Gmax; Gmin]];
gnuplotsave('pentane.dat', data);

figure()

subplot(1, 2, 1)
plot(xcoarse, Gcoarse, '-b', data.box(:,1), data.box(:,2), '-k')
ylabel('G', 'rotation', 0);
xlabel('\epsilon');

subplot(1, 2, 2)
plot(xfine, Gfine, '-b')
xlabel('\epsilon');