-
Notifications
You must be signed in to change notification settings - Fork 0
/
disc.py
47 lines (35 loc) · 783 Bytes
/
disc.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
import numpy as np
def tri_disc(N, a):
M0r = np.zeros(N)
M0r[0] = 1+a
M0r[1] = -a
M1r = np.zeros(N)
M1r[0] = -a
M1r[1] = 1+2*a
M1r[2] = -a
Mlr = np.zeros(N)
Mlr[-2] = -a
Mlr[-1] = 1+a
M = np.zeros((N, N))
M[0] = M0r
M[1] = M1r
M[-1] = Mlr
for i in range(2,N-1):
M[i] = np.roll(M[i-1], 1)
return M
def conv_mat(N, a, b):
M1r = np.zeros(N*N)
M1r[1] = a
M1r[N] = a
M1r[N+1] = b
M1r[N+2] = a
M1r[2*N+1] = a
M = np.zeros(((N-2)**2, N**2))
M[0] = M1r
jump = (N-2)*(np.arange(1,(N-2)**2)-1)+1
for i in range(1,(N-2)*(N-2)):
if i+1 in jump[1:]:
M[i] = np.roll(M[i-1], 3)
else:
M[i] = np.roll(M[i-1], 1)
return M