-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevp_matrix.py
More file actions
29 lines (24 loc) · 630 Bytes
/
evp_matrix.py
File metadata and controls
29 lines (24 loc) · 630 Bytes
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
# Author: Alex Gezerlis
# Numerical Methods in Physics with Python (CUP, 2020)
from qrmet import qrmet
import numpy as np
def matsetup(q,n):
h = 2*np.pi/n
xs = np.arange(n)*h
A = np.zeros((n,n))
np.fill_diagonal(A, -2 - 2*h**2*q*np.cos(2*xs))
np.fill_diagonal(A[1:,:], 1)
np.fill_diagonal(A[:,1:], 1)
A[0,-1] = 1
A[-1,0] = 1
return A
def mathieu(q,n):
A = matsetup(q, n)
qreigvals = qrmet(A,200)
h = 2*np.pi/n
qreigvals = np.sort(-qreigvals/h**2)
return qreigvals
if __name__ == '__main__':
q, n = 1.5, 200
qreigvals = mathieu(q, n)
print(qreigvals[:6])