-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp24.py
47 lines (40 loc) · 994 Bytes
/
p24.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
"""p24.py - psuedospectra of Davies' complex harmonic oscillator"""
import numpy as np
import scipy.linalg as la
from cheb import cheb
import matplotlib.pyplot as plt
from alive_progress import alive_bar
# Eigenvalues
n = 70
D, x = cheb(n)
x = x[1:n]
L = 6
x = L * x # recale to [-L, L]
D = D / L
A = -D @ D
A = A[1:n, 1:n] + (1 + 3j) * np.diag(x**2)
eigs = np.linalg.eigvals(A)
plt.plot(eigs.real, eigs.imag, "k.", markersize=8)
plt.xlim(0, 50)
plt.ylim(0, 40)
# Pseudospectra
x = np.arange(0, 50.1, 2) # For finer, slower plot, change 2 to 0.5
y = np.arange(0, 40.1, 2)
xx, yy = np.meshgrid(x, y)
zz = xx + 1j * yy
I = np.eye(n - 1) # noqa: E741
sig_min = np.zeros((len(y), len(x)))
with alive_bar(len(x)) as bar:
for j in range(len(x)):
bar()
for i in range(len(y)):
sig_min[i, j] = la.svdvals(zz[i, j] * I - A)[-1]
plt.contour(
x,
y,
sig_min,
10.0 ** np.arange(-4, -0.25, 0.5),
colors="black",
linewidths=0.75,
)
plt.show()