Figure 3.3:

Gibbs energy G versus reaction extent \varepsilon '.

Figure 3.3

Code for Figure 3.3

Text of the GNU GPL.

main.py


 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
# Converted from pentane.m
import numpy as np
from misc import gnuplotsave
from collections import OrderedDict

K = 108.0
P = 2.5

def xlogx(x):
    with np.errstate(divide='ignore', invalid='ignore'):
        result = np.where(x > 0, x * np.log(x), 0.0)
    return result

def G(x):
    return (-x * np.log(K) + (1 - x) * np.log(P) +
            xlogx(x) + 2*xlogx(0.5 - x) - xlogx(1 - x))

npts = 100
xcoarse = np.linspace(0, 0.5, npts)
Gcoarse = G(xcoarse)

xfine = np.linspace(0.45, 0.5, npts)
Gfine = G(xfine)

Gmin = np.min(Gfine) - 0.025
Gmax = np.max(Gfine) + 0.025
xbox = np.array([xfine[0], xfine[-1], xfine[-1], xfine[0], xfine[0]])
ybox = np.array([Gmin, Gmin, Gmax, Gmax, Gmin])

data = OrderedDict()
data['coarse'] = np.column_stack([xcoarse, Gcoarse])
data['fine'] = np.column_stack([xfine, Gfine])
data['box'] = np.column_stack([xbox, ybox])
gnuplotsave('pentane.dat', data)