Figure 2.17:

Landscape for H=\frac {1}{2}p^{2}+\frac {1}{4}q^{4}-\frac {1}{2}q^{2}.

Code for Figure 2.17

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
import numpy as np
import matplotlib.pyplot as plt

n = 101
x = np.linspace(-1.5, 1.5, n)
y = np.linspace(-1.0, 1.0, n)

xx, yy = np.meshgrid(x, y)
xx2 = np.power(xx, 2)
xx4 = np.power(xx2, 2)
yy2 = np.power(yy, 2)

z = 0.5 * yy2 + 0.25 * xx4 - 0.5 * xx2

val = [-0.2, -0.1, 0, 0.1, 0.2, 0.3, 0.4]
contour_fig, ax = plt.subplots()
c = ax.contour(x, y, z.T, levels=val)
ax.axis([-1.5, 1.5, -1, 1])
ax.set_xlabel("$q$")
ax.text(-1.7, 0, "$p$")
plt.savefig("homoclinic.eps", format='eps')
plt.show(block=False)

with open('homoclinic.dat', 'w') as myfile:
    for i, collection in enumerate(c.collections):
        paths = collection.get_paths()
        for path in paths:
            np.savetxt(myfile, path.vertices, fmt='%f')
            myfile.write('\n\n')