def roots(self): from numpy.lib.scimath import sqrt as csqrt r1 = (-self.b - csqrt((self.b**2) - (4 * self.a * self.c))) / (2 * self.a) r2 = (-self.b + csqrt((self.b**2) - (4 * self.a * self.c))) / (2 * self.a) return r1, r2
def Mf(t0, t): # define a function to compute the M matrix Int_w1d = Id for i in range(Ndim): w1d = w1d_num[i](t) w1d0 = w1d_num[i](t0) dw1d0 = dw1d_num[i](t0) g0 = gamma_num[i](t0) Int_gamma = quad(gamma_num[i], t0, t, args=(), maxiter=quad_maxiter, vec_func=False)[0] Int_w1d = c_quad(w1d_num[i], t0, t, ARGS=(), MAXITER=quad_maxiter) C = np.exp(-0.5 * Int_gamma) * np.cos(Int_w1d) * csqrt( w1d0 / w1d) S = np.exp(-0.5 * Int_gamma) * np.sin(Int_w1d) * csqrt( w1d0 / w1d) M11[i, i] = C + S * (g0 / (2 * w1d0) + dw1d0 / (2 * (w1d0)**2)) M12[i, i] = S / w1d0 M_ = (M11 + M12 @ A_num(t0)) return M_
def roots(a, b, c): r1 = (-b + csqrt(b**2 - 4 * a * c)) / (2 * a) r2 = (-b - csqrt(b**2 - 4 * a * c)) / (2 * a) print(r1.imag, "imaginario") print(r2.real, "real") return r1, r2 #si no regreso nada no muestra nada
def i2(w, wp, k, v): gv = g(w, wp) e1 = csqrt((w + wp)**2 - 1) e2 = csqrt(wp**2 - 1) f_upper = f(k, np.real(e1 - e2), np.imag(e1 + e2) + 2 * v) * (gv + 1) f_lower = f(k, np.real(e1 + e2), np.imag(e1 + e2) + 2 * v) * (gv - 1) return f_upper + f_lower
def components(self): """list of ProjectiveCollection: The components of the degenerate quadrics.""" n = self.shape[-1] indices = tuple(np.indices(self.shape[:-2])) if n == 3: b = adjugate(self.array) i = np.argmax(np.abs(np.diagonal(b, axis1=-2, axis2=-1)), axis=-1) beta = csqrt(-b[indices + (i, i)]) p = -b[indices + (slice(None), i)] / np.where(beta != 0, beta, -1)[..., None] else: ind = np.indices((n, n)) ind = [ np.delete(np.delete(ind, i, axis=1), i, axis=2) for i in combinations(range(n), n - 2) ] ind = np.stack(ind, axis=1) minors = det(self.array[..., ind[0], ind[1]]) p = csqrt(-minors) # use the skew symmetric matrix m to get a matrix of rank 1 defining the same quadric m = hat_matrix(p) t = self.array + m # components are in the non-zero rows and columns (up to scalar multiple) i = np.unravel_index( np.abs(t).reshape(t.shape[:-2] + (-1, )).argmax(axis=-1), t.shape[-2:]) p, q = t[indices + i[:1]], t[indices + (slice(None), i[1])] if self.dim > 2 and not np.all( is_multiple( q[..., None] * p[..., None, :], t, rtol=EQ_TOL_REL, atol=EQ_TOL_ABS, axis=(-2, -1), )): raise NotReducible("Quadric has no decomposition in 2 components.") # TODO: make order of components reproducible p, q = np.real_if_close(p), np.real_if_close(q) if self.is_dual: return [ PointCollection(p, copy=False), PointCollection(q, copy=False) ] elif n == 3: return [ LineCollection(p, copy=False), LineCollection(q, copy=False) ] return [PlaneCollection(p, copy=False), PlaneCollection(q, copy=False)]
def Mf(t0, t): # define a function to compute the M matrix w1 = w1_num[i](t) w10 = w1_num[i](t0) dw10 = dw1_num[i](t0) Int_w1 = c_quad(w1_num[i], t0, t, ARGS=(), MAXITER=quad_maxiter) C = np.cos(Int_w1)*csqrt(w10/w1) S = np.sin(Int_w1)*csqrt(w10/w1) M11[i,i] = C + S*dw10/(2*(w10)**2) M12[i,i] = S/w10
def Mf(t0, t): # define a function to compute the M matrix for i in range(Ndim): w1 = w1_num[i](t) w10 = w1_num[i](t0) dw10 = dw1_num[i](t0) Int_w1 = c_quad(w1_num[i], t0, t, ARGS=(), MAXITER=quad_maxiter) C = np.cos(Int_w1)*csqrt(w10/w1) S = np.sin(Int_w1)*csqrt(w10/w1) M11[i,i] = C + S*dw10/(2*(w10)**2) M12[i,i] = S/w10 M_ = P_num(t) @ (M11 @ Pinv_num(t0) + M12 @ (dPinv_num(t0) + Pinv_num(t0) @ A_num(t0))) return M_
def Mf(t0, t): # define a function to compute the M matrix for i in range(Ndim): w1 = w1_num[i](t) w10 = w1_num[i](t0) dw10 = dw1_num[i](t0) Int_w1 = c_quad(w1_num[i], t0, t, ARGS=()) C = np.cos(Int_w1)*csqrt(w10/w1) S = np.sin(Int_w1)*csqrt(w10/w1) M11[i,i] = C + S*dw10/(2*(w10)**2) M12[i,i] = S/w10 M_ = (M11 + M12 @ A_num(t0)) return M_
def components(self): """:obj:`list` of :obj:`ProjectiveElement`: The components of a degenerate conic.""" a = csqrt(-np.linalg.det(self.array[[[1], [2]], [1, 2]])) b = csqrt(-np.linalg.det(self.array[[[0], [2]], [0, 2]])) c = csqrt(-np.linalg.det(self.array[[[0], [1]], [0, 1]])) m = np.array([[0, c, -b], [-c, 0, a], [b, -a, 0]]) t = self.array + m i = np.unravel_index(np.abs(t).argmax(), t.shape) if self.is_dual: return [Point(t[i[0]]), Point(t[:, i[1]])] return [Line(t[i[0]]), Line(t[:, i[1]])]
def Mf(t0, t): # define a function to compute the M matrix w1 = w1_vec(t) w10 = w1_vec(t0) dw10 = dw1(t0) for i in range(Ndim): Int_w1 = c_quad(w1_sing, t0, t, ARGS=(i)) C = np.cos(Int_w1)*csqrt(w10[i]/w1[i]) S = np.sin(Int_w1)*csqrt(w10[i]/w1[i]) M11[i,i] = C + S*dw10[i]/(2*(w10[i])**2) M12[i,i] = S/w10[i] Pinvt0 = dPinv_num(t0) M_ = P_num(t) @ (M11 @ Pinvt0 + M12 @ () + Pinvt0 @ A_num(t0)) return M_
def Mf(t0, t): # define a function to compute the M matrix w1 = w1_vec(t) w10 = w1_vec(t0) dw10 = dw1(t0) Int_w1 = Id for i in range(Ndim): Int_w1 = c_quad(w1_sing, t0, t, ARGS=(i), MAXITER=quad_maxiter) C = np.cos(Int_w1) * csqrt(w10[i] / w1[i]) S = np.sin(Int_w1) * csqrt(w10[i] / w1[i]) M11[i, i] = C + S * dw10[i] / (2 * (w10[i])**2) M12[i, i] = S / w10[i] M_ = (M11 + M12 @ A_num(t0)) return M_
def omega(s, s_0, alpha): """A conformal variable. Parameters ---------- s the Mandelstam variable `s` s_0 usually non-negative. Above `s_0`, the conformal variable is complex. alpha the center of the conformal expansion """ sqrt_s = csqrt(s) diff = alpha * csqrt(s_0 - s) return (sqrt_s - diff) / (sqrt_s + diff)
def Mf(t0, t): # define a function to compute the M matrix w1 = w1_vec(t) w10 = w1_vec(t0) dw10 = dw1(t0) Int_w1 = Id for i in range(Ndim): Int_w1 = quad(w1_sing, t0, t, args=(i, True), maxiter=10)[0] + 1j*quad(w1_sing, t0, t, args=(i, False), maxiter=10)[0] C = np.cos(Int_w1)*csqrt(w10[i]/w1[i]) S = np.sin(Int_w1)*csqrt(w10[i]/w1[i]) M11[i,i] = C + S*dw10[i]/(2*(w10[i])**2) M12[i,i] = S/w1[i] Pinv = np.linalg.inv(P(t)) M_ = Pinv @ (M11 @ P(t0) + M12 @ (dP(t0) + P(t0) @ A_num(t0))) return M_
def diagonalize_isotropic(permittivity, settings): # pylint: disable=too-many-locals """Diagonalizes propagation matrix for a homogeneous pattern. The diagonalization is done by hand to ensure appropriate ordering of s and p polarizations. The ith (i + g_num)th eigenvector and eigenvalue correspond to the s- (p-) polarization of the ith diffraction order. The input and output arguments are the same as for diagonalize_structured except for the first input argument, which is a 3-element list of permittivities instead of a pattern. """ g_num = settings['g_num'] frequency = settings['frequency'] kx_vec = settings['kx_vec'] ky_vec = settings['ky_vec'] k_perp_mat = np.vstack((-np.diag(ky_vec), np.diag(kx_vec))) k_norm = np.sqrt(kx_vec**2 + ky_vec**2) eig_vals_s = permittivity[0] * frequency**2 - k_norm**2 eig_vals_s = csqrt(eig_vals_s) eig_vals_s[np.imag(eig_vals_s) < 0] *= -1 eig_vals_p = permittivity[0] * (frequency**2 - k_norm**2 / permittivity[2]) eig_vals_p = csqrt(eig_vals_p) eig_vals_p[np.imag(eig_vals_p) < 0] *= -1 eig_vals = np.hstack((eig_vals_s, eig_vals_p)) if np.any(abs(eig_vals) / frequency < config.TOL): raise RuntimeError("Encountered a mode that does not propagate " "out of plane (q = 0). The current implementation " "of pyPho is incapable of handling this situation " ":(") ind = (k_norm / frequency < config.TOL) ind = np.where(ind)[0] k_norm[ind] = 1 eig_vecs_s = k_perp_mat / k_norm eig_vecs_s[:, ind] = 0 eig_vecs_s[g_num + ind, ind] = 1 eig_vecs_p = np.vstack((np.diag(kx_vec), np.diag(ky_vec))) / k_norm eig_vecs_p[:, ind] = 0 eig_vecs_p[ind, ind] = 1 eig_vecs_p = eig_vecs_p * eig_vals_p / (csqrt(permittivity[0] * frequency)) eig_vecs_e = np.hstack((eig_vecs_s, eig_vecs_p)) eig_vecs_h = -(permittivity[0] * frequency**2 * np.eye(2 * g_num) - k_perp_mat @ k_perp_mat.T) @ eig_vecs_e / (frequency * eig_vals) return eig_vals, eig_vecs_e, eig_vecs_h
def w1_sing(t, n): Ap2_ = Aprime2_num(t) w2 = -J_[n, n] if w2.size > 1: w2 = w2[0] w1_ = np.asscalar(csqrt(w2)) return w1_
def Mf(t0, t): # define a function to compute the M matrix Int_w1d = Id for i in range(Ndim): w1d = w1d_num[i](t) w1d0 = w1d_num[i](t0) dw1d0 = dw1d_num[i](t0) g0 = gamma_num[i](t0) Int_gamma = c_quad(gamma_num[i], t0, t) Int_w1d = c_quad(w1d_num[i], t0, t) C = np.exp(-0.5*Int_gamma)*np.cos(Int_w1d)*csqrt(w1d0/w1d) S = np.exp(-0.5*Int_gamma)*np.sin(Int_w1d)*csqrt(w1d0/w1d) M11[i,i] = C + S*(g0/(2*w1d0) + dw1d0/(2*(w1d0)**2)) M12[i,i] = S/w1d0 M_ = (M11 + M12 @ A_num(t0)) return M_
def w1_sing(t, n): A_ = Ap(t) w2 = -A_[n, n] if w2.size > 1: w2 = w2[0] w1_ = np.asscalar(csqrt(w2)) return w1_
def q_resonator(M): A = M[0, 0] B = M[0, 1] C = M[1, 0] D = M[1, 1] q = (-(D - A) + csqrt((D - A)**2 + 4 * B * C)) / (2 * np.abs(C)) return q
def ForwardModel(resistivities, thicknesses, frequency): MU = 4*np.pi*10**(-7) w = 2*np.pi * frequency n = len(resistivities) impedances = np.zeros(n, dtype='complex_') # print('================================================================') # print(n) # print(resistivities) # print(thicknesses) # print('================================================================') impedances[n-1] = csqrt( csqrt(-1) * w * MU * float(resistivities[n-1]) ) if n > 1: for j in range(n-2,-1,-1): resistivity = float(resistivities[j]) thickness = float(thicknesses[j]) dj = csqrt(csqrt(-1) * (w * MU / resistivity )) wj = dj * resistivity ej = np.exp(-2 * thickness * dj) belowImpedance = impedances[j+1] rj = (wj - belowImpedance) / (wj + belowImpedance) re = rj * ej Zj = wj * ((1 - re) / (1 + re)) impedances[j] = Zj Z = impedances[0] absZ = abs(Z) apparentResistivity = absZ * absZ / (MU * w) phase = np.rad2deg( np.arctan2(np.imag(Z), np.real(Z)) ) return apparentResistivity, phase
def from_tangent(cls, tangent, a, b, c, d): """Construct a conic through four points and tangent to a line. Parameters ---------- tangent : Line a, b, c, d : Point The points lying on the conic. Returns ------- Conic The resulting conic. """ if any(tangent.contains(p) for p in [a, b, c, d]): raise ValueError( "The supplied points cannot lie on the supplied tangent!") a1, a2 = ( Line(a, c).meet(tangent).normalized_array, Line(b, d).meet(tangent).normalized_array, ) b1, b2 = ( Line(a, b).meet(tangent).normalized_array, Line(c, d).meet(tangent).normalized_array, ) o = tangent.general_point.array a2b1 = det([o, a2, b1]) a2b2 = det([o, a2, b2]) a1b1 = det([o, a1, b1]) a1b2 = det([o, a1, b2]) c1 = csqrt(a2b1 * a2b2) c2 = csqrt(a1b1 * a1b2) x = Point(c1 * a1 + c2 * a2, copy=False) y = Point(c1 * a1 - c2 * a2, copy=False) conic = cls.from_points(a, b, c, d, x) if np.all(np.isreal(conic.array)): return conic return cls.from_points(a, b, c, d, y)
def w1_vec(t): A_ = Ap(t) w1_ = np.ones(Ndim).astype(np.complex64) for n in range(Ndim): w2 = -A_[n, n] if w2.size > 1: w2 = w2[0] w1_[n] = np.asscalar(csqrt(w2)) return w1_
def components(self): """:obj:`list` of :obj:`ProjectiveElement`: The components of a degenerate conic.""" if not self.is_degenerate: return [self] a = csqrt(-np.linalg.det(self.matrix[np.array([1,2])[:, np.newaxis], np.array([1,2])])) b = csqrt(-np.linalg.det(self.matrix[np.array([0,2])[:, np.newaxis], np.array([0,2])])) c = csqrt(-np.linalg.det(self.matrix[np.array([0,1])[:, np.newaxis], np.array([0,1])])) m = np.array([[0, c, -b], [-c, 0, a], [b, -a, 0]]) t = self.matrix + m x, y = np.nonzero(t) result = [] for a in np.concatenate((t[x,:], t[:,y].T)): l = Point(a) if self.is_dual else Line(a) if l not in result: result.append(l) return result
def w1_sing(t, n): if Use_Aprime2_or_J: W2 = -Aprime2_num(t) elif not Use_Aprime2_or_J: W2 = -J_num(t) w2 = W2[n, n] if w2.size > 1: w2 = w2[0] w1_ = np.asscalar(csqrt(w2)) return w1_
def w1_sing(t, n, real): J_ = J(t) w2 = -J_[n,n] if w2.size > 1: w2 = w2[0] w1_ = np.asscalar(csqrt(w2)) if real: w1_ = np.real(w1_) elif not real: w1_ = np.imag(w1_) return w1_
def calc_anomalies(a, phi0): khat = np.array([np.cos(phi0), np.sin(phi0)]) x1 = (h*khat[0] + (h*khat[1])[:, np.newaxis]) / a # print(x1) x2 = (h/a)**2 x3 = x1**2 - (x2 + x2[:, np.newaxis]) + 1 # mask = np.where(x3 > 0, True, False) minuspart = -x1 - csqrt(x3) pluspart = -x1 + csqrt(x3) # print(sin_theta0) anomaly_theta0 = [] for item in minuspart.flatten(): if item.imag == 0 and 0 < item.real < np.pi/2: anomaly_theta0.append(item) for item in pluspart.flatten(): if item.imag == 0 and 0 < item.real < np.pi/2: anomaly_theta0.append(item) return np.arcsin(np.array(anomaly_theta0)) * 180 / np.pi
def twoloop(self, z, p): s = p[0] g = p[1:] r_in, a, b = np.array(g, dtype=np.complex128) * mm r = r_in + a / 2 Rsq = r + a**2 / 24 / r c = csqrt((b**2 - a**2) / 12) pterm = (Rsq + c)**2 / (z**2 + (Rsq + c)**2)**(1.5) mterm = (Rsq - c)**2 / (z**2 + (Rsq - c)**2)**(1.5) B = 1 / 4 * const.mu_0 * s * (pterm + mterm) return np.real(B) # complex part is 0 anyways
def w1_vec(t): if Use_Aprime2_or_J: W2 = -Aprime2_num(t) elif not Use_Aprime2_or_J: W2 = -J_num(t) w1_ = np.ones(Ndim).astype(np.complex64) for n in range(Ndim): w2 = W2[n,n] if w2.size > 1: w2 = w2[0] w1_[n] = np.asscalar(csqrt(w2)) return w1_
def components(self): """list of ProjectiveElement: The components of a degenerate quadric.""" # Algorithm adapted from Perspectives on Projective Geometry, Section 11.1 n = self.shape[0] if n == 3: b = adjugate(self.array) i = np.argmax(np.abs(np.diag(b))) beta = csqrt(-b[i, i]) p = -b[:, i] / beta if beta != 0 else b[:, i] else: p = [] for ind in combinations(range(n), n - 2): # calculate all principal minors of order 2 row_ind = [[j] for j in range(n) if j not in ind] col_ind = [j for j in range(n) if j not in ind] p.append(csqrt(-det(self.array[row_ind, col_ind]))) # use the skew symmetric matrix m to get a matrix of rank 1 defining the same quadric m = hat_matrix(p) t = self.array + m # components are in the non-zero rows and columns (up to scalar multiple) i = np.unravel_index(np.abs(t).argmax(), t.shape) p, q = t[i[0]], t[:, i[1]] if self.dim > 2 and not is_multiple( np.outer(q, p), t, rtol=EQ_TOL_REL, atol=EQ_TOL_ABS): raise NotReducible("Quadric has no decomposition in 2 components.") p, q = np.real_if_close(p), np.real_if_close(q) if self.is_dual: return [Point(p, copy=False), Point(q, copy=False)] elif n == 3: return [Line(p, copy=False), Line(q, copy=False)] return [Plane(p, copy=False), Plane(q, copy=False)]
def spemiss(f, tk, theta, ssw): ''' * returns the specular emissivity of sea water for given freq. (GHz), * temperature T (K), incidence angle theta (degrees), salinity (permil) * * Returned values verified against data in Klein and Swift (1977) and * against Table 3.8 in Olson (1987, Ph.D. Thesis) * ''' from numpy.lib.scimath import sqrt as csqrt #implicit none #real*4 f,tk,theta,ssw,ev,eh #real*4 fold,tkold,sswold,epsr,epsi,epsrold,epsiold #save fold,tkold,sswold,epsrold,epsiold #* #real*4 tc,costh,sinth,rthet #complex*8 etav,etah,eps,cterm1v,cterm1h,cterm2,cterm3v,cterm3h #* # <------------ !!! This section has been modified #if ((f != fold) | (tk != tkold) | (ssw < sswold)): # tc = tk - 273.15 # fold = f # tkold = tk # sswold = ssw tc = tk - 273.15 epsr, epsi = epsalt(f, tc, ssw) epsrold = epsr epsiold = epsi #else: #epsr = epsrold #epsi = epsiold eps = epsr + 1.0j * epsi #cmplx(epsr,epsi) etav = eps etah = 1.0 + 1.0j * 0.0 #(1.0, 0.0) rthet = theta * 0.017453292 costh = np.cos(rthet) sinth = np.sin(rthet) sinth = sinth * sinth cterm1v = etav * costh cterm1h = etah * costh eps = eps - sinth cterm2 = csqrt(eps) # <---------- csqrt cterm3v = (cterm1v - cterm2) / (cterm1v + cterm2) cterm3h = (cterm1h - cterm2) / (cterm1h + cterm2) #print('cterm3v: {}, cterm3h: {}'.format(cterm3v, cterm3h)) ev = 1.0 - np.abs(cterm3v)**2 #cabs(cterm3v)**2 eh = 1.0 - np.abs(cterm3h)**2 #cabs(cterm3h)**2 return ev, eh
def calculate(self, parameters): A = parameters["A"] b = parameters["b"] A, b = process_params(A, b) response = self.init_response() if no_es_invertible(A): response["error"] = "La matriz no es invertible" return response if not es_definida_positiva(A): response["error"] = "La matriz no definida positiva" return response n = len(A) # L = np.zeros((n, n)) # U = np.zeros((n, n)) # Utilizar estas si se quiere trabajar con complejos L = np.zeros((n, n), dtype="complex") U = np.zeros((n, n), dtype="complex") for k in range(n): suma1 = np.sum([L[k, p] * U[p, k] for p in range(0, k)]) L[k, k] = U[k, k] = csqrt(A[k, k] - suma1) for i in range(k + 1, n): suma2 = np.sum(L[i, p] * U[p, k] for p in range(0, k)) L[i, k] = (A[i, k] - suma2) / U[k, k] for j in range(k + 1, n): suma3 = np.sum(L[k, p] * U[p, j] for p in range(0, k)) U[k, j] = (A[k, j] - suma3) / L[k, k] z = self.sustitucion_progresiva(L, b) x = self.sustitucion_regresiva(U, z) L = np.real(L) U = np.real(U) response["L"] = np.round(L, 4).tolist() response["U"] = np.round(U, 4).tolist() response["z"] = np.round(np.real(z), 4).tolist() response["x"] = np.round(np.real(x), 4).tolist() return response
def get_target(self): """ Build a reflectance image of the target and calculate surface normals at every pixel """ # Set up pixel relative x-coodinates x = np.linspace(-1.0, 1.0, self.n_pix * self.anti_aliasing) # Meshgrid the x and y coordinates as the same x, y = np.meshgrid(x, x) # Calculate the polar coordinate theta of each pixel theta = np.arctan2(y, x) # Produce a siemens star target with the given number of spokes/sectors siemans_star = np.cos(self.Nsector_pairs * theta) # Create an array that will become a target mask mask = np.ones(siemans_star.shape) # Make the mask binary by taking the sign of the siemens star siemans_star = np.sign(siemans_star)/2.0 + 0.5 # Set all value outside the unit circle to the new value circle = np.sqrt(x**2 + y**2) > 1.0 mask[circle] = 0.0 # downsample if aliasing requested if self.anti_aliasing > 1.0: the_filter = np.ones((self.anti_aliasing, self.anti_aliasing)) / self.anti_aliasing**2 # Apply 2D filter convolution siemans_star = sg.convolve2d(siemans_star, the_filter, mode = 'full') # Convole the mask as well mask = sg.convolve2d(mask, the_filter, mode = 'full') siemans_star = siemans_star[0.0::self.anti_aliasing, ::self.anti_aliasing] mask = mask[0.0::self.anti_aliasing, ::self.anti_aliasing] x = np.linspace(-1.0, 1.0, siemans_star.shape[0]) y = np.linspace(-1.0, 1.0, siemans_star.shape[1]) x, y = np.meshgrid(x, y) # Create blank list of normal vector components normal_vector_list = [[],[],[]] normal_vector_list[0] = x normal_vector_list[1] = y normal_vector_list[2] = (csqrt(1.0 - x**2 - y**2)).real # Save reflectance map, normal vectors and mask in self self.normal_vector_list = normal_vector_list self.siemens_star = siemans_star self.mask = mask return normal_vector_list, mask, siemans_star
def get_supercritical_velocity_array(self): """Calculate the supercritical velocity for the given temperature or pressure range.""" v_array_calculation = csqrt(2 * 1000 * (self.get_enthalpy_column() - self.get_mean_enthalpy_at_tp())) v_array = np.where(np.iscomplex(v_array_calculation), 0, v_array_calculation).astype(float) return v_array
# Raised Cosine z = np.linspace(-Length/2,Length/2,no_sections) delta_n = 0.5*d_n_max*(1+np.cos(np.pi*(z/(0.1*Length)))) for i in range(0,lambda_points): MAT = np.eye(2) for m in range(no_sections-1,0,-1): kapadc = 4*np.pi*delta_n[m]/wavelength[i] kapaac = kapadc/2 delta = kapadc+0.5*(2*ko[i]*n_eff[i]-2*np.pi/period) alpha = csqrt(kapaac**2-delta**2) T = TMM(period, dz, delta_n[m], delta, alpha,dz) MAT =np.dot(MAT,T) R[i] = np.abs(MAT[0,1]/MAT[0,0]) plt.figure(2) plt.plot(wavelength,R) plt.figure(3) plt.plot(z,delta_n) plt.show()