-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
164 lines (130 loc) · 3.8 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import numpy as np
from scipy.optimize import NonlinearConstraint, minimize
import scipy
import matplotlib.pyplot as plt
import sys
import os
cwd = os.getcwd()
def get_K_(s, x, n):
N = len(x)-1
K_s = 0
if n < N-1:
xn0 = x[n]
xn = x[n+1]
xn1 = x[n+2]
a0 = 0
a = 0
a1 = 0
if (s==xn0):
a = (s-xn) * np.log(xn-s+0j)
a1 = (s-xn1) * np.log(xn1-s+0j)
elif (s==xn):
a0 = (s-xn0) * np.log(xn0-s+0j)
a1 = (s-xn1) * np.log(xn1-s+0j)
elif (s==xn1):
a0 = (s-xn0) * np.log(xn0-s+0j)
a = (s-xn) * np.log(xn-s+0j)
else:
a0 = (s-xn0) * np.log(xn0-s+0j)
a = (s-xn) * np.log(xn-s+0j)
a1 = (s-xn1) * np.log(xn1-s+0j)
K_s = K_s + a0/(xn0-xn) + a1/(xn-xn1) - ((xn0-xn1)*a)/((xn0-xn)*(xn-xn1))
else:
xN0 = x[N-1]
xN = x[N]
a0 = 0
a = 0
if (s==xN0):
a = (s-xN) * np.log(xN-s+0j)
elif (s==xN):
a0 = (s-xN0) * np.log(xN0-s+0j)
else:
a = (s-xN) * np.log(xN-s+0j)
a0 = (s-xN0) * np.log(xN0-s+0j)
K_s = K_s + a0/(xN0-xN) + (xN/s)*np.log(xN+0j) + (xN0-xN-s)*a/(s*(xN0-xN)) + 1
return K_s
def K_(x, s_range):
'''
if s_range == None:
s_range = x[1:]
'''
M = len(s_range)
N = len(x)-1
K = np.zeros((M,N), dtype=complex)
for m in range(M):
s = s_range[m]
t = 4-s
for n in range(N):
K[m,n] = get_K_(s, x, n) + get_K_(t, x, n)
return K
def get_K_re_(s, x, n):
N = len(x)-1
K_s = 0
if n < N-1:
xn0 = x[n]
xn = x[n+1]
xn1 = x[n+2]
a0 = 0
a = 0
a1 = 0
if (s==xn0):
a = (s-xn) * np.log(np.abs(xn-s))
a1 = (s-xn1) * np.log(np.abs(xn1-s))
elif (s==xn):
a0 = (s-xn0) * np.log(np.abs(xn0-s))
a1 = (s-xn1) * np.log(np.abs(xn1-s))
elif (s==xn1):
a0 = (s-xn0) * np.log(np.abs(xn0-s))
a = (s-xn) * np.log(np.abs(xn-s))
else:
a0 = (s-xn0) * np.log(np.abs(xn0-s))
a = (s-xn) * np.log(np.abs(xn-s))
a1 = (s-xn1) * np.log(np.abs(xn1-s))
K_s = K_s + a0/(xn0-xn) + a1/(xn-xn1) - ((xn0-xn1)*a)/((xn0-xn)*(xn-xn1))
else:
xN0 = x[N-1]
xN = x[N]
a0 = 0
a = 0
if (s==xN0):
a = (s-xN) * np.log(np.abs(xN-s))
elif (s==xN):
a0 = (s-xN0) * np.log(np.abs(xN0-s))
else:
a = (s-xN) * np.log(np.abs(xN-s))
a0 = (s-xN0) * np.log(np.abs(xN0-s))
K_s = K_s + a0/(xN0-xN) + (xN/s)*np.log(xN) + (xN0-xN-s)*a/(s*(xN0-xN)) + 1
return K_s
def K_Re_(x, s_range):
'''
if s_range == None:
s_range = x[1:]
'''
M = len(s_range)
N = len(x)-1
K_re = np.zeros((M,N), dtype=float)
for m in range(M):
s = s_range[m]
t = 4-s
for n in range(N):
K_re[m,n] = get_K_re_(s, x, n) + get_K_re_(t, x, n)
return K_re
def Pole_(s_range, m_spec):
m2 = m_spec**2
J = 1/(2*m_spec * np.sqrt(4-m2))
M = len(s_range)
n_m = len(m_spec)
poles = np.zeros((M,n_m), dtype = float)
for i in range(M):
s = s_range[i]
t = 4-s
poles[i,:] = -J * ( 1/(s-m2) + 1/(t-m2) )
return poles
def Con_(var, K_re, poles, n_m):
#c = np.zeros(n_con, dtype=float)
c = np.zeros(K_re.shape[0] + 1, dtype=float)
S_inf = var[-1]
V = np.matmul(poles, var[0:n_m]) + np.matmul(K_re, var[n_m: -1])
c[0:-1] = (S_inf + V)**2 + (np.pi * var[n_m: -1])**2 ### Assuming s_range == xgrid[1:]
c[-1] = S_inf**2
return c