def derivTy(z,y,x,t): r_w_z_2_1 = (y**2+x**2)/w1(z)**2 r_w_z_2_2 = ((z+pos(t))**2+y**2)/w2(x)**2 lag_1 = eval_genlaguerre(p,l,2*r_w_z_2_1) lag_2 = eval_genlaguerre(p,l,2*r_w_z_2_2) return (w0/w1(z))**2*(2*r_w_z_2_1)**(l-1)*np.exp(-2*r_w_z_2_1)*lag_1*(4*y/w1(z)**2)*((l-2*r_w_z_2_1)*lag_1+4*r_w_z_2_1*np.polyval(np.polyder(genlaguerre(p,l)),2*r_w_z_2_1))+(w0/w2(x))**2*(2*r_w_z_2_2)**(l-1)*np.exp(-2*r_w_z_2_2)*lag_2*(4*y/w2(x)**2)*((l-2*r_w_z_2_2)*lag_2+4*r_w_z_2_2*np.polyval(np.polyder(genlaguerre(p,l)),2*r_w_z_2_2))
def get_displace_op_matrix_element(m, n, alpha): r'''Get matrix elements from a displacement operator. The number-basis elements are :math:`\langle m|\exp(\alpha a^\dagger - \alpha^* a)|n\rangle` Parameters ---------- m: nonnegative integer Number index for the row of the matrix element n: nonnegative integer Number index for the column of the matrix element alpha: complex number Displacement amplitude Returns ------- complex number Number-basis matrix element of the displacement operator ''' abs_alpha_sq = np.abs(alpha)**2 if m >= n: return (np.sqrt(factorial(n) / factorial(m)) * np.exp(-abs_alpha_sq / 2) * alpha**(m - n) * eval_genlaguerre(n, m - n, abs_alpha_sq)) return (np.sqrt(factorial(m) / factorial(n)) * np.exp(-abs_alpha_sq / 2) * np.conj(-alpha)**(n - m) * eval_genlaguerre(m, n - m, abs_alpha_sq))
def derivTx(z,y,x,t): r_w_z_2_1 = (y**2+x**2)/w1(z)**2 r_w_z_2_2 = ((z+pos(t))**2+y**2)/w2(x)**2 lag_1 = eval_genlaguerre(p,l,2*r_w_z_2_1) lag_2 = eval_genlaguerre(p,l,2*r_w_z_2_2) return (w0/w1(z))**2*(2*r_w_z_2_1)**(l-1)*np.exp(-2*r_w_z_2_1)*lag_1*(4*x/w1(z)**2)*((l-2*r_w_z_2_1)*lag_1+4*r_w_z_2_1*np.polyval(np.polyder(genlaguerre(p,l)),2*r_w_z_2_1))+np.exp(-2*r_w_z_2_2)*lag_2*2*(2*r_w_z_2_2)**l*la2**2*x/np.pi**2/w2(x)**4*((-(1+l)+2*r_w_z_2_2)*lag_2-4*r_w_z_2_2*np.polyval(np.polyder(genlaguerre(p,l)),2*r_w_z_2_2))
def It0(z, y, x, t): D = 0.5 #Unitary intensity #Amplitude added in the force expression r_w_z_2_1 = (y**2 + x**2) / w1(z)**2 r_w_z_2_2 = ((z + pos(t))**2 + y**2) / w2(x)**2 return (w0 / w1(z))**2 * (2 * r_w_z_2_1)**l * np.exp( -2 * r_w_z_2_1) * eval_genlaguerre(p, l, 2 * r_w_z_2_1)**2 + ( w0 / w2(x))**2 * (2 * r_w_z_2_2)**l * np.exp( -2 * r_w_z_2_2) * eval_genlaguerre(p, l, 2 * r_w_z_2_2)**2
def ddpsi(r, n, l, nu): N = np.sqrt( np.sqrt(2. * (nu**3) / np.pi) * (2.**(n + 2 * l + 3) * nu**l * np.exp(log_fact(n) - log_d_fact(2 * n + 2 * l + 1)))) ddpsi = np.exp(-r**2 * nu) * ( 16. * r** (4 + l - 1) * nu**2 * eval_genlaguerre(n - 2, l + 2.5, 2 * nu * r**2) + 4. * r**(2 + l - 1) * nu * (-3 - 2 * l + 4 * r**2 * nu) * eval_genlaguerre(n - 1, l + 1.5, 2 * nu * r**2) + r**(l - 1) * (l * (l + 1) - 2 * (3 + 2 * l) * r**2 * nu + 4 * r**4 * nu**2) * eval_genlaguerre(n, l + 0.5, 2 * nu * r**2)) return N * ddpsi
def test_laguerre(): allTrue = True for order in range(ORDER_MAX): x = np.random.rand(1).item() valuePy = sp.eval_laguerre(order, x) valueCpp = NumCpp.laguerre_Scaler1(order, x) if np.round(valuePy, DECIMALS_ROUND) != np.round(valueCpp, DECIMALS_ROUND): allTrue = False assert allTrue allTrue = True for order in range(ORDER_MAX): shapeInput = np.random.randint(10, 100, [2, ], dtype=np.uint32) shape = NumCpp.Shape(*shapeInput) cArray = NumCpp.NdArray(shape) x = np.random.rand(*shapeInput) cArray.setArray(x) valuePy = sp.eval_laguerre(order, x) valueCpp = NumCpp.laguerre_Array1(order, cArray) if not np.array_equal(np.round(valuePy, DECIMALS_ROUND), np.round(valueCpp, DECIMALS_ROUND)): allTrue = False assert allTrue allTrue = True for order in range(ORDER_MAX): degree = np.random.randint(0, 10, [1, ]).item() x = np.random.rand(1).item() valuePy = sp.eval_genlaguerre(degree, order, x) valueCpp = NumCpp.laguerre_Scaler2(order, degree, x) if np.round(valuePy, DECIMALS_ROUND) != np.round(valueCpp, DECIMALS_ROUND): allTrue = False assert allTrue allTrue = True for order in range(ORDER_MAX): degree = np.random.randint(0, 10, [1, ]).item() shapeInput = np.random.randint(10, 100, [2, ], dtype=np.uint32) shape = NumCpp.Shape(*shapeInput) cArray = NumCpp.NdArray(shape) x = np.random.rand(*shapeInput) cArray.setArray(x) valuePy = sp.eval_genlaguerre(degree, order, x) valueCpp = NumCpp.laguerre_Array2(order, degree, cArray) if not np.array_equal(np.round(valuePy, DECIMALS_ROUND), np.round(valueCpp, DECIMALS_ROUND)): allTrue = False assert allTrue
def test_laguerre(): if NumCpp.NO_USE_BOOST and not NumCpp.STL_SPECIAL_FUNCTIONS: return for order in range(ORDER_MAX): x = np.random.rand(1).item() valuePy = sp.eval_laguerre(order, x) valueCpp = NumCpp.laguerre_Scaler1(order, x) assert np.round(valuePy, DECIMALS_ROUND) == np.round(valueCpp, DECIMALS_ROUND) for order in range(ORDER_MAX): shapeInput = np.random.randint(10, 100, [ 2, ], dtype=np.uint32) shape = NumCpp.Shape(*shapeInput) cArray = NumCpp.NdArray(shape) x = np.random.rand(*shapeInput) cArray.setArray(x) valuePy = sp.eval_laguerre(order, x) valueCpp = NumCpp.laguerre_Array1(order, cArray) assert np.array_equal(np.round(valuePy, DECIMALS_ROUND), np.round(valueCpp, DECIMALS_ROUND)) for order in range(ORDER_MAX): degree = np.random.randint(0, 10, [ 1, ]).item() x = np.random.rand(1).item() valuePy = sp.eval_genlaguerre(degree, order, x) valueCpp = NumCpp.laguerre_Scaler2(order, degree, x) assert np.round(valuePy, DECIMALS_ROUND) == np.round(valueCpp, DECIMALS_ROUND) for order in range(ORDER_MAX): degree = np.random.randint(0, 10, [ 1, ]).item() shapeInput = np.random.randint(10, 100, [ 2, ], dtype=np.uint32) shape = NumCpp.Shape(*shapeInput) cArray = NumCpp.NdArray(shape) x = np.random.rand(*shapeInput) cArray.setArray(x) valuePy = sp.eval_genlaguerre(degree, order, x) valueCpp = NumCpp.laguerre_Array2(order, degree, cArray) assert np.array_equal(np.round(valuePy, DECIMALS_ROUND), np.round(valueCpp, DECIMALS_ROUND))
def derivTy(z, y, x): r_w_z_2 = (y**2 + x**2) / w(z)**2 lag = eval_genlaguerre(p, l, 2 * r_w_z_2) return (w0 / w(z))**2 * (2 * r_w_z_2)**(l - 1) * np.exp( -2 * r_w_z_2) * lag * (4 * y / w(z)**2) * ( (l - 2 * r_w_z_2) * lag + 4 * r_w_z_2 * np.polyval(np.polyder(genlaguerre(p, l)), 2 * r_w_z_2))
def radial(r, n, l): p = 2 * r / (n * a) lag_gen = eval_genlaguerre(n - l - 1, 2 * l + 1, p) y = np.sqrt( (2 / (n * a))**3 * np.math.factorial(n - l - 1) / (2 * n * np.math.factorial(n + l))) * np.exp(-p / 2) * p**l * lag_gen return y
def _first_family(self, fact, num_timepoints, num_orthogonal_family_members, omega, psi_zero): beta = np.reshape(self.beta, self.beta.shape + (1, 1)) gamma = np.reshape(self.gamma, self.gamma.shape + (1, 1)) r = (2 * beta + 1) / gamma c = r - 1 # ([1, ..., 1,] freq, time) laguerre = np.zeros_like(omega) indices = np.arange(int(np.ceil(num_timepoints / 2))) # (wavelet, ..., freq, time) psi_f = np.zeros(((num_orthogonal_family_members,) + psi_zero.shape), dtype=psi_zero.dtype) for k in range(num_orthogonal_family_members): if self.is_bandpass_normalized: coeff = np.where( beta == 0, 1, np.sqrt( np.exp(scipy.special.gammaln(r) + scipy.special.gammaln(k + 1) - scipy.special.gammaln(k + r)))) else: # (freq, time) coeff = np.sqrt(1 / fact) * self.amplitude(k + 1) laguerre[..., indices] = eval_genlaguerre(k, c, 2 * np.power(omega[..., indices], gamma)) psi_f[k] = coeff * psi_zero * laguerre # either eliminate the family-order axis or move the family-order axis to -3 if num_orthogonal_family_members == 1: psi_f = np.squeeze(psi_f, 0) else: psi_f = np.moveaxis(psi_f, 0, -3) # (..., [wavelet,], freq, time) return psi_f
def derivTz(z, y, x): r_w_z_2 = (y**2 + x**2) / w(z)**2 lag = eval_genlaguerre(p, l, 2 * r_w_z_2) return np.exp(-2 * r_w_z_2) * lag * 2 * ( 2 * r_w_z_2)**l * la**2 * z / np.pi**2 / w(z)**4 * ( (-(1 + l) + 2 * r_w_z_2) * lag - 4 * r_w_z_2 * np.polyval(np.polyder(genlaguerre(p, l)), 2 * r_w_z_2))
def scalar_angular_spectrum(self, theta, phi, k): Lpl = eval_genlaguerre(self.p, abs(self.l), 0.5 * (k * self.width * np.tan(theta))**2) exp = np.exp(-(k * self.width * np.tan(theta) / 2)**2) phase = np.exp(1j * self.l * phi) amp = 1j * (k * self.width * np.tan(theta) / np.sqrt(2))**abs(self.l) return amp * Lpl * exp * phase
def psi(r, n, l, nu): N = np.sqrt( np.sqrt(2. * (nu**3) / np.pi) * (2.**(n + 2 * l + 3) * nu**l * np.exp(log_fact(n) - log_d_fact(2 * n + 2 * l + 1)))) psi = r * N * r**l * np.exp(-nu * r**2) * eval_genlaguerre( n, l + 0.5, 2 * nu * r**2) return psi
def LG(x, y, z=0, l=0, p=0, w_0=2e-6, lam=1.97e-12): """Generates a Laguerre-Gauss spatial mode. Note: broadcasting is not supported - if x and y are both 1d arrays, the result will be a 1darray and will NOT make sense. Likewise if x, y are 2d arrays, but z is a 1d array, the result will be an error. **Parameters** * **x** : _number, ndarray_ <br /> The x-coordinates over which to calculate the beam. * **y** : _number, ndarray_ <br /> The y-coordinates over which to calculate the beam. * **z** : _number, ndarray, optional_ <br /> The z-coordinates over which to calculate the beam. <br /> Default is `z = 0`. * **l** : _number, optional_ <br /> The winding number, or chirality, of the beam. <br /> Default is `l = 0`. * **p** : _number, optional_ <br /> The radial index of the beam. <br /> Default is `p = 0`. * **w_0** : _number, optional_ <br /> The beam waist. <br /> Default is `w_0 = 2e-6`. * **lam** : _number, optional_ <br /> The beam's wavelength. <br /> Default is `lam = 1.97e-12` (the relativistic wavelength of a 300keV electron). **Returns** * **mode** : _ndarray_ <br /> The complex amplitudes of a Laguerre Gaussian beam at the specified x, y, and z positions. """ r, theta = np.sqrt(x**2 + y**2), np.arctan2(y, x) Clp = np.sqrt(2 * factorial(p) / np.pi / factorial(p + np.abs(l))) z_r = np.pi * w_0**2 / lam w_z = w_0 * np.sqrt(1 + z**2 / z_r**2) gouy = (2 * p + np.abs(l) + 1) * np.nan_to_num(np.arctan2(z, z_r)) r = np.sqrt(x**2 + y**2) theta = np.arctan2(y, x) mode = Clp \ * w_0/w_z \ * (r * np.sqrt(2)/w_z)**np.abs(l) \ * np.exp(-r**2/w_z**2) \ * eval_genlaguerre(p,np.abs(l),(2*r**2)/w_z**2) \ * np.exp(-1j * 2 * np.pi / lam * r**2 * z/ 2 /(z**2 + z_r**2)) \ * np.exp(-1j * l * theta) \ * np.exp(1j * (1 + np.abs(l) * 2*p)) mode /= np.max(np.abs(mode)) return (mode)
def matel(x, i, j): n = min(i, j) m = max(i, j) factor = (-0.5)**((m-n)/2.) \ *1./np.sqrt(special.poch(n+1,m-n)) \ *x**(m-n) \ *np.exp(-0.25*x**2) \ *special.eval_genlaguerre(n, m-n, 0.5*x**2) return factor
def P(m): ''' Find the probability of finding m molecules, using the generating function P(m) = sum_i 1/m! (d/ds)^m G_i(s=0). Uses normal Python capabilities; limited usage for beyond certain parameter space m: number of molcules ''' m1 = m + 1 P0 = 1 / (1 + z) #eq unoccupancy, coeff in G0 L0 = sp.eval_genlaguerre(-z * x, z * x + x, 0) #other factor c_L = P0 / L0 #coeff of Laguerre function L_m = sp.eval_genlaguerre( -z * x - m, z * x + x + m, -y ) #mth derivative of Laguerre at s=0, using its derivative property + chain rule L_m1 = sp.eval_genlaguerre(-z * x - m1, z * x + x + m1, -y) #m+1th derivative of Laguerre at s=0 P = (z + 1 + m / x) * L_m + y * L_m1 / x P *= (-y)**m return (c_L * P / sp.factorial(m, exact=True))
def radial_psi(r, n, l, a0=1.0, z=1.0): """ Radial wavefunction for hydrogen electron orbital. """ rho = (2.0 * z * r) / (n * a0) sub = n - l - 1.0 sup = 2.0 * l + 1.0 normFactor = np.sqrt((2.0 * z / (n * a0))**3 * misc.factorial(sub) / (2.0 * n * misc.factorial(n + l))) wf = (rho**l * np.exp(-rho / 2.0) * eval_genlaguerre(sub, sup, rho)) return wf * normFactor
def polar_basis_L(r, n0, m0, beta=1.): """Polar dimensional basis function based on Laguerre polynomials of characteristic size beta phs: additional phase factor, used in the Fourier Transform""" m_a = abs(m0) n_m = (n0 - m_a)/2 n_p = (n0 + m_a)/2 # 2π is missing here.. norm = (-1.)**n_m/(beta**(m_a + 1))*(float(factorial(n_m))/factorial(n_p))**.5 lag = eval_genlaguerre(n_m, m_a, (r/beta)**2) return neval('norm*lag*r**m_a*exp(-.5*(r/beta)**2)')
def R(n, l, r): # normalized radius #rho = 2.0 * r / (n * R_BOHR) rho = 2.0 * r / n # first term, a normalization constant with respect to n and l term_1 = np.sqrt((8.0 * special.factorial(n - l - 1)) / (n**3 * 2.0 * n * special.factorial(n + l))) # second term, exp(-0.5 * rho) * rho^l term_2 = np.exp(-0.5 * rho) * np.power(rho, l) # third term, a generalized Laguerre polynomial term_3 = special.eval_genlaguerre(n - l - 1, 2 * l + 1, rho) return term_1 * term_2 * term_3
def R(n, l, r): '''Returns the radial wavefunction for each value of r where n is the principle quantum number and l is the angular momentum quantum number.''' y = np.zeros(numValues) #Generates an associated laguerre polynomial as a scipy.special.orthogonal.orthopoly1d Lag = eval_genlaguerre(n - l - 1, 2 * l + 1) #Loops through each power of r in the laguerre polynomial and adds to the total for i in range(len(Lag) + 1): i = float(i) #The main equation (What its all about) y = y + (((2 * r / (n * a))**(l)) * (np.exp(-r / (a * n))) * Lag[int(i)] * (((2 * r) / (a * n))**i)) return y
def gaussian_laguerre(p, l, mode_field_diameter=1, grid=None): r'''Creates a Gaussian-Laguerre mode. This function evaluates a (p,l) order Gaussian-Laguerre mode on a grid. The definition of the modes are the following, .. math:: \exp{\left(-\frac{r^2}{w_0^2}\right)} L_p^{|l|}\left(\frac{2r^2}{w_0^2} \right) \left(\sqrt{2}\frac{r}{w_0}\right) Here :math:`w_0` is the mode_field_radius, which is :math:`\mathrm{MFD}/2`. And :math:`L_p^{|l|}` are the generalized Laguerre Polynomials. All modes are numerical normalized to have a total power of 1. More details on generalized Laguerre Polynomials can be found on: http://mathworld.wolfram.com/AssociatedLaguerrePolynomial.html Parameters ---------- p : int The radial order. l : int The azimuthal order. mode_field_diameter : scalar The mode field diameter of the mode. grid : Grid The grid on which to evaluate the mode. Returns ------- Field The evaluated mode. ''' from ..field import Field if grid.is_separated and grid.is_('polar'): R, Theta = grid.separated_coords else: R, Theta = grid.as_('polar').coords # Easy access r = 2 * R / mode_field_diameter r2 = r**2 # Compute the mode lg = (r * sqrt(2))**abs(l) * np.exp(-r2) * np.exp( -1j * l * Theta) * eval_genlaguerre(p, abs(l), 2 * r2) # Numerically normalize the mode lg /= np.sqrt(np.sum(np.abs(lg)**2 * grid.weights)) return Field(lg, grid)
def coupling(self, n, m, phi): """ Return the out diagonal terms of the Hamiltonian matrix in GHz. Parameters ---------- n : int Row number m : int Column number phi : float Reduced flux Φ_ext/Φ_0. Returns ---------- Energies : np.array Eigenenergies of the matrix """ # temp variable a = np.sqrt(8.*self.Ec/self.El) # We compute only the part of the fraction which is not simplified # afterwards b = np.sqrt(1./np.array(range(m+1)[n+1:], float).prod()) # If m - n is odd if (m - n)%2: return -self.Ej*np.sin(phi*np.pi*2.)*np.sqrt(2.**n/2.**m)\ *a**((m - n)/2.)*b*(-1.)**((m - n - 1.)/2.)\ *np.exp(-a/4.)*eval_genlaguerre(n, m - n, a/2.) # If it is even else: return -self.Ej*np.cos(phi*np.pi*2.)*np.sqrt(2.**n/2.**m)\ *a**((m - n)/2.)*b*(-1.)**((m - n)/2.)\ *np.exp(-a/4.)*eval_genlaguerre(n, m - n, a/2.)
def Om_genrabi(Om_rabi,eta_LD,n,s): ''' returns the generalized rabi frequency Omega_{n,n+s} Om_rabi: on-resonance carrier rabi-frequency eta_LD: lambda dicke parameter = np.sqrt( hbar/(2*m*Om_sec) ) n: starting motional stateob s: change in motional state, e.g. s = -1, driving on the -1 sideband. ''' FactorialRatio = 1 / np.sqrt((reduce(operator.mul,range(n,n+abs(s),1),1))) return Om_rabi*np.exp(-eta_LD**2/2.0)*eta_LD**(abs(s))*FactorialRatio*(special.eval_genlaguerre(n,abs(s),eta_LD**2))
def gap_function_diagonal_quadratic(n, k_range, mesh_size, amplitude = 1): import numpy as np import scipy.special as sps mesh = np.meshgrid(np.linspace(-1,1,mesh_size),np.linspace(-1,1,mesh_size)) output = np.zeros(mesh[0].shape) for k in range(-k_range, k_range): output = output + np.exp(np.pi*(2*1j*k*mesh[1] - (0.5*mesh[0] + k)**2))*sps.eval_genlaguerre(n, -0.5, 2*np.pi*((0.5*mesh[0] + k)**2)) output = np.abs(output) output = amplitude*output return output, mesh
def radial_function(self, r: float): """Return the radial part of the wavefunction, R, evaluated at r.""" normalization = np.sqrt( ((2 / (self.n * u.bohr_radius)) ** 3) * ( special.factorial(self.n - self.l - 1) / (2 * self.n * special.factorial(self.n + self.l)) ) ) # Griffith's normalization r_dep = np.exp(-r / (self.n * u.bohr_radius)) * ( (2 * r / (self.n * u.bohr_radius)) ** self.l ) lag_poly = special.eval_genlaguerre( self.n - self.l - 1, (2 * self.l) + 1, 2 * r / (self.n * u.bohr_radius) ) return self.amplitude * normalization * r_dep * lag_poly
def psi_f(self, freqs: np.ndarray, scale: float = 1, k: int = 0): """Wavelet function in the frequency domain. By default, they are normalized to have unitary norm. Parameters ---------- freqs : np.ndarray Array of frequency values. scale : float Scale factor. k : int Order of the wavelet. """ r = (2 * self.beta + 1) / self.gamma # I calculate the log to avoid exploding functions and improve the # numerical precision, particularly for the Γ(k + 1)/Γ(k + r). if self.norm == 'energy': logA = 0.5 * (np.log(np.pi * self.gamma / scale) + (r + 1) * np.log(2) + loggamma(k + 1) - loggamma(k + r)) else: logA = np.log(2 / scale) + self.beta / self.gamma * ( 1 + np.log(self.gamma / self.beta)) # The frequency in radians aω = scale * 2 * np.pi * freqs H = np.heaviside(aω, 0.5) # As before, I use the log instead of doing a ω^beta. with np.errstate(divide='ignore', invalid='ignore'): wav0 = scale * H * \ np.exp(logA - aω ** self.gamma + self.beta * np.log(aω)) # Remove the term which explosed. Not very elegant, but it works. if np.isscalar(wav0): wav0 = 0 if np.isnan(wav0) else wav0 else: wav0[np.isnan(wav0)] = 0 # Finally, I add the generalized Laguerre polynomial term. return wav0 * eval_genlaguerre(k, r - 1, 2 * aω**self.gamma)
def gen_rab_freq(n0=0, n1=1, omega0=1.0, eta=0.1): """calculate rabi frequency associated with single photon, n0->n1 transition all inputs may be vectors n0, n1: SHM excitation states of the transition omega: strength of coupling term (would be rabi frequency if not for lamb-dicke effect) eta: lamb-dicke parameter returns rabi frequency of transition (vector if inputs are vectors) """ n_s, n_l = np.sort(np.array([n0, n1]), axis=0) return omega0 * np.exp(-eta*eta/2) \ * np.sqrt(factorial(n_s)/factorial(n_l)) \ * eta**(n_l-n_s) * eval_genlaguerre(n_s, n_l-n_s, eta*eta)
def test_roots_genlaguerre(): rootf = lambda a: lambda n, mu: sc.roots_genlaguerre(n, a, mu) evalf = lambda a: lambda n, x: sc.eval_genlaguerre(n, a, x) weightf = lambda a: lambda x: x**a * np.exp(-x) vgq = verify_gauss_quad vgq(rootf(-0.5), evalf(-0.5), weightf(-0.5), 0., np.inf, 5) vgq(rootf(-0.5), evalf(-0.5), weightf(-0.5), 0., np.inf, 25, atol=1e-13) vgq(rootf(-0.5), evalf(-0.5), weightf(-0.5), 0., np.inf, 100, atol=1e-12) vgq(rootf(0.1), evalf(0.1), weightf(0.1), 0., np.inf, 5) vgq(rootf(0.1), evalf(0.1), weightf(0.1), 0., np.inf, 25, atol=1e-13) vgq(rootf(0.1), evalf(0.1), weightf(0.1), 0., np.inf, 100, atol=1.6e-13) vgq(rootf(1), evalf(1), weightf(1), 0., np.inf, 5) vgq(rootf(1), evalf(1), weightf(1), 0., np.inf, 25, atol=1e-13) vgq(rootf(1), evalf(1), weightf(1), 0., np.inf, 100, atol=1.03e-13) vgq(rootf(10), evalf(10), weightf(10), 0., np.inf, 5) vgq(rootf(10), evalf(10), weightf(10), 0., np.inf, 25, atol=1e-13) vgq(rootf(10), evalf(10), weightf(10), 0., np.inf, 100, atol=1e-12) vgq(rootf(50), evalf(50), weightf(50), 0., np.inf, 5) vgq(rootf(50), evalf(50), weightf(50), 0., np.inf, 25, atol=1e-13) vgq(rootf(50), evalf(50), weightf(50), 0., np.inf, 100, rtol=1e-14, atol=2e-13) x, w = sc.roots_genlaguerre(5, 2, False) y, v, m = sc.roots_genlaguerre(5, 2, True) assert_allclose(x, y, 1e-14, 1e-14) assert_allclose(w, v, 1e-14, 1e-14) muI, muI_err = integrate.quad(weightf(2.), 0., np.inf) assert_allclose(m, muI, rtol=muI_err) assert_raises(ValueError, sc.roots_genlaguerre, 0, 2) assert_raises(ValueError, sc.roots_genlaguerre, 3.3, 2) assert_raises(ValueError, sc.roots_genlaguerre, 3, -1.1)
def laguerre_gaussian_paraxial(src, x, y, z, k): E0 = np.sqrt((2 * Z0 * src.power)) rho_sq = x**2 + y**2 phi = np.arctan2(y, x) wav = 2 * np.pi / k C = np.sqrt(2 * factorial(src.p) / (np.pi * factorial(src.p + abs(src.l)))) wz = w(z, src.width, wav) Lpl = eval_genlaguerre(src.p, abs(src.l), 2 * rho_sq / wz**2) N = abs(src.l) + 2 * src.p amp = E0 * C / wz * np.exp(-rho_sq / wz**2) * ( (2 * rho_sq)**0.5 / wz)**abs(src.l) * Lpl phase = src.l * phi + k * z + k * rho_sq * Rinv( z, src.width, wav) / 2 - (N + 1) * gouy(z, src.width, wav) return amp * np.exp(1j * phase)
def sphprod_gauss(n): ''' Spherical product Gauss rule: A rule of order 2*n-1 making use of the separation of variables in polar coordinates. If n is even, it uses n**2 points, lying on n/2 regular 2n-gons; if n is odd, it uses n**2 - n + 1 points, with n*(n-1) of them lying on (n-1)/2 regular 2n-gons and one lying at the origin. ''' theta = np.linspace(-(1 - 1 / (2 * n)) * pi, (1 - 1 / (2 * n)) * pi, 2 * n) theta_weights = np.full(2 * n, pi / n) if n % 2 == 1: rsquared = ray.gauss_genlaguerre(n // 2, 1)[0] r = sqrt(rsquared) even_orders = np.arange(0, (n + 1) // 2) rsquared = np.concatenate((np.zeros(1), rsquared)) rsquared = rsquared[:, np.newaxis] evens = special.eval_laguerre(even_orders, rsquared)**2 evens = np.sum(evens, axis=1) odd_orders = np.arange(0, (n - 1) // 2) odds = special.eval_genlaguerre(odd_orders, 1, rsquared)**2 odds = np.sum(rsquared / (odd_orders + 1) * odds, axis=1) r_weights = 1 / (evens + odds) x_nodes = np.tile(r, 2 * n) * np.repeat(cos(theta), n // 2) x_nodes = np.concatenate((np.zeros(1), x_nodes)) y_nodes = np.tile(r, 2 * n) * np.repeat(sin(theta), n // 2) y_nodes = np.concatenate((np.zeros(1), y_nodes)) weights = np.tile(r_weights[1:], 2 * n) * np.repeat( theta_weights, n // 2) weights = np.concatenate((pi * r_weights[0:1], weights)) else: rsquared, rsquared_weights = ray.gauss_laguerre(n // 2) r = sqrt(rsquared) r_weights = rsquared_weights / 2 x_nodes = np.tile(r, 2 * n) * np.repeat(cos(theta), n // 2) y_nodes = np.tile(r, 2 * n) * np.repeat(sin(theta), n // 2) weights = np.tile(r_weights, 2 * n) * np.repeat(theta_weights, n // 2) return (x_nodes, y_nodes), weights
def LG_pl(r, phi, l, p, z=0, wavelength=0.001, w0=1): # create laguerre gauss modes # define k vector, rayliegh range, beam waist k = 2 * np.pi / wavelength zR = (k * w0**2) / 2 wz = np.sqrt(2 * (z**2 + zR**2) / (k * zR)) al = abs(l) # define all coefficients cf1 = np.sqrt((2 * factorial(p)) / (factorial(al + p) * np.pi)) cf2 = ((r * np.sqrt(2)) / wz)**al cf3 = np.exp(-(r**2) / wz**2) cf4 = np.exp(1j * l * phi) cf5 = np.exp(1j * (k * z * r**2) / (2 * (z**2 + zR**2))) cf6 = np.exp(-1j * (2 * p + al + 1) * np.arctan(z / zR)) # Calculate lg mode LG = cf1 * cf2 * cf3 * cf4 * cf5 * cf6 * eval_genlaguerre( p, al, (2 * r**2) / wz**2) return (LG)
} } } } """ weave.inline(codel, ['Lag', 'x', 'alpha', 'max_n'], type_converters=weave.converters.blitz, compiler = 'gcc') return Lag if __name__ == '__main__': import sys from scipy import special max_n=100 alpha=1. x=10. Lag = Laguerre_dirty(x,alpha,max_n) for n in range(max_n+1): print 'laguerre=', n, special.eval_genlaguerre(n,alpha,x), Lag[n] m=1 max_l=30 x=0.999 Plm = Plmc(x,m,max_l) for il,l in enumerate(range(m,len(Plm)+m)): print 'Plm=', il,l,special.lpmv(m,l,x),Plm[il]
def NormHyller(x,m,p,Cks,M2mu2): #csum = sum([Cks[k]*special.eval_genlaguerre(m+k,m,x) for k in range(len(Cks))]) # original csum = sum([Cks[k]*special.eval_genlaguerre(k,m,x) for k in range(len(Cks))]) lambd = 1+x/(2*p) return (lambd**2-1)**m*exp(-x)*csum**2*(lambd**2-M2mu2)/(2*p)
def eval_genlaguerre_ddd(n, a, x): return eval_genlaguerre(n.astype('d'), a, x)
def eval_genlaguerre_ldd(n, a, x): return eval_genlaguerre(n.astype('l'), a, x)