-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.py
49 lines (43 loc) · 1.09 KB
/
utils.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
import numpy as np
def calc_rw(u):
# Set u0 to 1
utemp = np.copy(u)
utemp = utemp/u[0]
# Construct P
P = np.zeros((7,7))
P[0, 0] = 1.
for i in range(1,7):
P[i-1, 1] = ((-1.)**(i-1)) * u[i-1]
for j in range(3,8):
for i in range(1,7):
P[i-1, j-1] = P[0, j-2]*P[i, j-3] - P[0, j-3]*P[i,j-2]
# Construct alpha
alpha = np.zeros(6)
alpha[0] = 0
alpha[1] = u[1]
for n in range(3, 7):
alpha[n-1] = P[0, n] / (P[0, n-1] * P[0, n-2])
# Construct a, b
a = np.zeros(3)
b = np.zeros(2)
for n in range(1, 4):
a[n-1] = alpha[2*n-1] + alpha[2*n-2]
if n < 3:
b[n-1] = np.sqrt(np.abs(alpha[2*n]*alpha[2*n-1]))
# Construct Jacobian
J = np.zeros((3, 3))
J[0, 0] = a[0]
J[1, 1] = a[1]
J[2, 2] = a[2]
J[1, 0] = b[0]
J[0, 1] = b[0]
J[1, 2] = b[1]
J[2, 1] = b[1]
# Find Absicassas and Wieghts
r, evectors = np.linalg.eig(J)
r = r[::-1]
w = np.zeros(3)
for i in range(3):
w[i] = u[0] * evectors[0,i]**2
w = w[::-1]
return r, w