def nodes(n): left = mp.mpf(0) right = mp.mpf(n + (n - 1) * sqrt(n) * 1.01) i = 2 factor = 2 while True: l = [(x, mp.laguerre(n, 0, x)) for x in mp.linspace(left, right, n * factor**i)] intervals = [] for j in range(len(l) - 1): prod = l[j][1] * l[j + 1][1] if prod < 0: intervals.append([l[j][0], l[j + 1][0]]) if len(intervals) == n: break i += 1 roots = [] f = lambda x: mp.laguerre(n, 0, x) for ab in intervals: a, b = ab try: z = mp.findroot(f, (a, b), tol=1e-50, solver='bisect') except: z = bisect(f, a, b, tol=1e-50) roots.append(z) return roots
def nodes(n): left = mp.mpf(0) right = mp.mpf(n+(n-1)*sqrt(n)*1.01) i = 2 factor = 2 while True: l = [ (x,mp.laguerre(n,0,x)) for x in mp.linspace(left,right,n*factor**i)] intervals = [] for j in range(len(l)-1): prod = l[j][1]*l[j+1][1] if prod < 0: intervals.append([l[j][0], l[j+1][0]]) if len(intervals) == n: break i += 1 roots = [] f = lambda x: mp.laguerre(n,0,x) for ab in intervals: a,b = ab try: z = mp.findroot(f, (a, b), tol=1e-50, solver='bisect') except: z = bisect(f, a, b, tol=1e-50) roots.append( z ) return roots
def _displaced_thermal(cls, alpha, nbar, n): ''' returns the motional state distribution with the displacement alpha, motional temperature nbar for the state n ''' #this is needed because for some inputs (larrge n or small nbar, this term is 0 while the laguerre term is infinite. their product is zero but beyond the floating point precision try: old_settings = np.seterr(invalid='raise') populations = 1. / (nbar + 1.0) * (nbar / (nbar + 1.0))**n * laguerre( n, 0, -alpha**2 / (nbar * (nbar + 1.0))) * np.exp(-alpha**2 / (nbar + 1.0)) except FloatingPointError: np.seterr(**old_settings) print 'precise calculation required', alpha, nbar populations = [ mp.fprod((1. / (nbar + 1.0), mp.power(nbar / (nbar + 1.0), k), mp.laguerre(k, 0, -alpha**2 / (nbar * (nbar + 1.0))), mp.exp(-alpha**2 / (nbar + 1.0)))) for k in n ] print 'done computing populations' populations = np.array(populations) print 'returned array' return populations
def _displaced_thermal(cls, alpha, nbar, n): """ returns the motional state distribution with the displacement alpha, motional temperature nbar for the state n """ # this is needed because for some inputs (larrge n or small nbar, this term is 0 while the laguerre term is infinite. their product is zero but beyond the floating point precision try: old_settings = np.seterr(invalid="raise") populations = ( 1.0 / (nbar + 1.0) * (nbar / (nbar + 1.0)) ** n * laguerre(n, 0, -alpha ** 2 / (nbar * (nbar + 1.0))) * np.exp(-alpha ** 2 / (nbar + 1.0)) ) except FloatingPointError: np.seterr(**old_settings) print "precise calculation required", alpha, nbar populations = [ mp.fprod( ( 1.0 / (nbar + 1.0), mp.power(nbar / (nbar + 1.0), k), mp.laguerre(k, 0, -alpha ** 2 / (nbar * (nbar + 1.0))), mp.exp(-alpha ** 2 / (nbar + 1.0)), ) ) for k in n ] print "done computing populations" populations = np.array(populations) print "returned array" return populations
def ila_integrand_lp1(self, eta, rloc): k, p, l = self.k, self.p, self.l kz = mpmath.sqrt(k**2 - eta**2) res = mpmath.power(eta, np.abs(l) + 1) / mpmath.sqrt(kz) \ * mpmath.laguerre(p, l, self.a(eta) ** 2) * mpmath.exp(-self.a(eta) ** 2 / 2) \ * ((1 - kz / k) * mpmath.besselj(l + 2, eta * rloc / k) + (1 + kz / k) * mpmath.besselj(l, eta * rloc / k)) return res
def integrand(self, eta, l, p, n, kind="A"): if kind not in ("A", "B", "C", "D", "E"): raise NotImplementedError("Integrand types supported \ go only from A to E") if kind == "C": return (mpmath.sqrt(self.k ** 2 - eta ** 2) / eta \ * self.integrand(eta, l, p, n, kind="A")) if kind == "D": return (mpmath.sqrt(self.k ** 2 - eta ** 2) / eta \ * self.integrand(eta, l, p, n, kind="B")) pm = 1 exponent = n - 1 if kind == "B": pm = -1 elif kind == "E": pm = 0 exponent = n if p == 0: lgr_factor = 1 else: lgr_factor = (self.a(eta) ** 2 \ * mpmath.laguerre(p - 1, l, self.a(eta) ** 2)) kz = mpmath.sqrt(self.k**2 - eta**2) return ( mpmath.power(eta, np.abs(l) + 1) / mpmath.sqrt(kz) \ * mpmath.exp(-self.a(eta) ** 2 / 2) * (1 + pm * kz / self.k) \ * mpmath.power(eta / self.k, exponent) * lgr_factor)
def radial_integrand_lm1(self, eta, r, theta, phi): k = self.k kz = mpmath.sqrt(k**2 - eta**2) l, p = self.l, self.p a, b = self.alpha, self.beta result = (mpmath.power(eta, np.abs(l) + 1) / mpmath.sqrt(kz) \ * mpmath.laguerre(p, l, self.a(eta) ** 2) \ * mpmath.exp(-self.a(eta) ** 2 / 2 + 1j * (l - 1) * phi \ + 1j * kz * r * np.cos(theta)) \ * ((a + 1j * b) / 2 * (1 - kz / k) \ * mpmath.besselj(l - 2, eta * r * np.sin(theta)) \ * np.sin(theta) \ + eta / k * (1j * a - b) \ * mpmath.besselj(l - 1, eta * r * np.sin(theta)) \ * np.cos(theta) \ + (a + 1j * b) / 2 * (1 + kz / k) \ * mpmath.besselj(l, eta * r * np.sin(theta)) * np.sin(theta))) return result
def _displaced_thermal(cls, alpha, nbar, n): ''' returns the motional state distribution with the displacement alpha, motional temperature nbar for the state n ''' #this is needed because for some inputs (larrge n or small nbar, this term is 0 while the laguerre term is infinite. their product is zero but beyond the floating point precision try: old_settings = np.seterr(invalid='raise') populations = 1. / (nbar + 1.0) * (nbar / (nbar + 1.0))**n * laguerre( n, 0, -alpha**2 / (nbar * (nbar + 1.0))) * np.exp(-alpha**2 / (nbar + 1.0)) except FloatingPointError: np.seterr(**old_settings) def fib(): a, b = 0, 1 while 1: yield a a, b = b, a + b import time t1 = time.time() print 'precise calculation required', alpha, nbar expon_term = mp.exp(-alpha**2 / (nbar + 1.0)) populations = [ float( mp.fprod((mp.power(nbar / (nbar + 1.0), k), mp.laguerre(k, 0, -alpha**2 / (nbar * (nbar + 1.0))), expon))) for k in n ] populations = np.array(populations) / (nbar + 1) print time.time() - t1 print 'done' return populations
def _displaced_thermal(cls, alpha, nbar, n): ''' returns the motional state distribution with the displacement alpha, motional temperature nbar for the state n ''' #this is needed because for some inputs (larrge n or small nbar, this term is 0 while the laguerre term is infinite. their product is zero but beyond the floating point precision try: old_settings = np.seterr(invalid='raise') populations = 1./ (nbar + 1.0) * (nbar / (nbar + 1.0))**n * laguerre(n, 0 , -alpha**2 / ( nbar * (nbar + 1.0))) * np.exp( -alpha**2 / (nbar + 1.0)) except FloatingPointError: np.seterr(**old_settings) def fib(): a, b = 0, 1 while 1: yield a a, b = b, a + b import time t1 = time.time() print 'precise calculation required', alpha, nbar expon_term = mp.exp(-alpha**2 / (nbar + 1.0)) populations = [float(mp.fprod((mp.power(nbar / (nbar + 1.0), k), mp.laguerre(k, 0, -alpha**2 / ( nbar * (nbar + 1.0))), expon))) for k in n] populations = np.array(populations) / (nbar + 1) print time.time() - t1 print 'done' return populations
def func(channel): channell = [] for i in range(0,len(channel)): channell.append(float(mpmath.laguerre(degree,0,channel[i]))) return numpy.asarray(channell)
def wk(n, x): return x/((n+1)*mp.laguerre(n+1,0,x))**2
def wk(n, x): return x / ((n + 1) * mp.laguerre(n + 1, 0, x))**2