Figure B.2:

An attractive but unstable equilibrium at (r,\theta )=(1,0). Open circles are initial states.

Figure B.2

Code for Figure B.2

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Attractive but unstable equilibrium (r, theta) = (1, 0) of
#
#   r+ = sqrt(r)    theta+ = theta + (1/2)(1 - cos theta)
#
# Linearization at (1, 0): eigenvalue 1/2 along w1 (radial), 1 along w2
# (tangent to the unit circle).  The unit circle is a homoclinic orbit.
# Every motion with r(0) > 0 converges to (1, 0); a motion starting on the
# unit circle at theta(0) > 0, however small, travels once around the circle.
import os
import numpy as np
import matplotlib.pyplot as plt
from misc import gnuplotsave


def step(x, p):
    r, th = x
    c = p["c"]
    return np.array([np.sqrt(r), th + c*(1.0 - np.cos(th))])


p = {"c": 0.5}
nsteps = 400

# initial states (r(0), theta(0))
starts = np.array([[1.0, 0.15], [0.05, 0.6], [1.9, 0.5], [0.1, 4.0],
                   [1.5, 4.6], [0.22, 0.0], [1.9, 0.0],
                   [1.0, 2*np.pi - 0.9]])

data = {}
for j, x0 in enumerate(starts):
    x = np.empty((nsteps + 1, 2))
    x[0] = x0
    for k in range(nsteps):
        x[k + 1] = step(x[k], p)
    r, th = x[:, 0], x[:, 1]
    # trajectory in the plane, x1 = r cos theta, x2 = r sin theta
    data[f"traj{j + 1}"] = np.column_stack([r*np.cos(th), r*np.sin(th)])

if not os.getenv('OMIT_PLOTS') == 'true':
    phi = np.linspace(0, 2*np.pi, 400)
    plt.plot(np.cos(phi), np.sin(phi), color="0.6")
    for j in range(len(starts)):
        xy = data[f"traj{j + 1}"]
        plt.plot(xy[:, 0], xy[:, 1], "-o", ms=2)
        plt.plot(xy[0, 0], xy[0, 1], "ok", mfc="w")
    plt.axis("equal")
    plt.xlabel("x_1")
    plt.ylabel("x_2")

gnuplotsave("attractive_unstable.dat", data, fmt="%.10g")