我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用scipy.special.jv()。
def besselj(n, z): """Bessel function of first kind of order n at kr. Wraps scipy.special.jn(n, z). Parameters ---------- n : array_like Order kr: array_like Argument Returns ------- J : array_like Values of Bessel function of order n at position z """ return scy.jv(n, _np.complex_(z))
def Mie_ab(m,x): # http://pymiescatt.readthedocs.io/en/latest/forward.html#Mie_ab mx = m*x nmax = np.round(2+x+4*(x**(1/3))) nmx = np.round(max(nmax,np.abs(mx))+16) n = np.arange(1,nmax+1) nu = n + 0.5 sx = np.sqrt(0.5*np.pi*x) px = sx*jv(nu,x) p1x = np.append(np.sin(x), px[0:int(nmax)-1]) chx = -sx*yv(nu,x) ch1x = np.append(np.cos(x), chx[0:int(nmax)-1]) gsx = px-(0+1j)*chx gs1x = p1x-(0+1j)*ch1x # B&H Equation 4.89 Dn = np.zeros(int(nmx),dtype=complex) for i in range(int(nmx)-1,1,-1): Dn[i-1] = (i/mx)-(1/(Dn[i]+i/mx)) D = Dn[1:int(nmax)+1] # Dn(mx), drop terms beyond nMax da = D/m+n/x db = m*D+n/x an = (da*px-p1x)/(da*gsx-gs1x) bn = (db*px-p1x)/(db*gsx-gs1x) return an, bn
def Mie_cd(m,x): # http://pymiescatt.readthedocs.io/en/latest/forward.html#Mie_cd mx = m*x nmax = np.round(2+x+4*(x**(1/3))) nmx = np.round(max(nmax,np.abs(mx))+16) n = np.arange(1,int(nmax)+1) nu = n+0.5 cnx = np.zeros(int(nmx),dtype=complex) for j in np.arange(nmx,1,-1): cnx[int(j)-2] = j-mx*mx/(cnx[int(j)-1]+j) cnn = np.array([cnx[b] for b in range(0,len(n))]) jnx = np.sqrt(np.pi/(2*x))*jv(nu, x) jnmx = np.sqrt((2*mx)/np.pi)/jv(nu, mx) yx = np.sqrt(np.pi/(2*x))*yv(nu, x) hx = jnx+(1.0j)*yx b1x = np.append(np.sin(x)/x, jnx[0:int(nmax)-1]) y1x = np.append(-np.cos(x)/x, yx[0:int(nmax)-1]) hn1x = b1x+(1.0j)*y1x ax = x*b1x-n*jnx ahx = x*hn1x-n*hx numerator = jnx*ahx-hx*ax c_denominator = ahx-hx*cnn d_denominator = m*m*ahx-hx*cnn cn = jnmx*numerator/c_denominator dn = jnmx*m*numerator/d_denominator return cn, dn
def __init__(self, dim=7): assert dim == 7 centers = numpy.array([ [.1, .1, .1, .1, .1, .1, .1], [.3, .1, .5, .1, .8, .8, .6], [.6, .7, .8, .3, .7, .8, .6], [.7, 0, .7, 1, .3, 0, .8], [.4, .6, .4, 1, .4, .2, 1], [.5, .5, .2, .8, .5, .3, .4], [.1, .2, 1, .4, .5, .6, .7], [.9, .4, .3, .5, .2, .7, .2], [0, .5, .3, .2, .1, .9, .3], [.2, .8, .6, .4, .6, .6, .5], ]) e_mat = .7 * numpy.array([ [1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1], [.5, .5, .5, .5, .5, .5, .5], [1, 1, 1, 1, 1, 1, 1], [10, 10, 10, 10, 10, 10, 10], [.5, .5, .5, .5, .5, .5, .5], [1, 1, 1, 1, 1, 1, 1], [2, 2, 2, 2, 2, 2, 2], [1, 1, 1, 1, 1, 1, 1], ]) coefs = numpy.array([5, -4, 5, -5, -7, -2, 10, 2, -5, 5]) def kernel(x): r = numpy.sqrt(self.dist_sq(x, centers, e_mat)) return besselj(0, r) super(McCourt12, self).__init__(dim, kernel, e_mat, coefs, centers) self.min_loc = [0.4499, 0.4553, 0.0046, 1, 0.3784, 0.3067, 0.6173] self.fmin = 3.54274987790 self.fmax = 9.92924222433 self.classifiers = ['bound_min', 'oscillatory']
def __init__(self, dim=6): assert dim == 6 centers = numpy.array([ [0.1, 0.1, 1, 0.3, 0.4, 0.1], [0, 0, 0.1, 0.6, 0, 0.7], [0.1, 0.5, 0.7, 0, 0.7, 0.3], [0.9, 0.6, 0.2, 0.9, 0.3, 0.8], [0.8, 0.3, 0.7, 0.7, 0.2, 0.7], [0.7, 0.6, 0.5, 1, 1, 0.7], [0.8, 0.9, 0.5, 0, 0, 0.5], [0.3, 0, 0.3, 0.2, 0.1, 0.8], ]) e_mat = .1 * numpy.array([ [4, 5, 5, 4, 1, 5], [2, 4, 5, 1, 2, 2], [1, 4, 3, 2, 2, 3], [4, 2, 3, 4, 1, 4], [2, 3, 6, 6, 4, 1], [5, 4, 1, 4, 1, 1], [2, 2, 2, 5, 4, 2], [1, 4, 6, 3, 4, 3], ]) coefs = numpy.array([1, -2, 3, -20, 5, -2, -1, -2]) def kernel(x): rmax = self.dist_sq(x, centers, e_mat, dist_type='inf') return besselj(0, rmax) super(McCourt23, self).__init__(dim, kernel, e_mat, coefs, centers) self.min_loc = [0.7268, 0.3914, 0, 0.7268, 0.5375, 0.8229] self.fmin = -18.35750245671 self.fmax = -16.07462900440 self.classifiers = ['nonsmooth', 'bound_min']
def CoreShell_ab(mCore,mShell,xCore,xShell): # http://pymiescatt.readthedocs.io/en/latest/forwardCS.html#CoreShell_ab m = mShell/mCore u = mCore*xCore v = mShell*xCore w = mShell*xShell mx = max(np.abs(mCore*xShell),np.abs(mShell*xShell)) nmax = np.round(2+xShell+4*(xShell**(1/3))) nmx = np.round(max(nmax,mx)+16) n = np.arange(1,nmax+1) nu = n+0.5 sv = np.sqrt(0.5*np.pi*v) sw = np.sqrt(0.5*np.pi*w) sy = np.sqrt(0.5*np.pi*xShell) pv = sv*jv(nu,v) pw = sw*jv(nu,w) py = sy*jv(nu,xShell) chv = -sv*yv(nu,v) chw = -sw*yv(nu,w) chy = -sy*yv(nu,xShell) p1y = np.append([np.sin(xShell)], [py[0:int(nmax)-1]]) ch1y = np.append([np.cos(xShell)], [chy[0:int(nmax)-1]]) gsy = py-(0+1.0j)*chy gs1y = p1y-(0+1.0j)*ch1y # B&H Equation 4.89 Dnu = np.zeros((int(nmx)),dtype=complex) Dnv = np.zeros((int(nmx)),dtype=complex) Dnw = np.zeros((int(nmx)),dtype=complex) for i in range(int(nmx)-1,1,-1): Dnu[i-1] = i/u-1/(Dnu[i]+i/u) Dnv[i-1] = i/v-1/(Dnv[i]+i/v) Dnw[i-1] = i/w-1/(Dnw[i]+i/w) Du = Dnu[1:int(nmax)+1] Dv = Dnv[1:int(nmax)+1] Dw = Dnw[1:int(nmax)+1] uu = m*Du-Dv vv = Du/m-Dv fv = pv/chv dns = ((uu*fv/pw)/(uu*(pw-chw*fv)+(pw/pv)/chv))+Dw gns = ((vv*fv/pw)/(vv*(pw-chw*fv)+(pw/pv)/chv))+Dw a1 = dns/mShell+n/xShell b1 = mShell*gns+n/xShell an = (py*a1-p1y)/(gsy*a1-gs1y) bn = (py*b1-p1y)/(gsy*b1-gs1y) return an, bn
def circ_radial_weights(N, kr, setup): r"""Radial weighing functions. Computes the radial weighting functions for diferent array types For instance for an rigid array .. math:: b_n(kr) = J_n(kr) - \frac{J_n^\prime(kr)}{H_n^{(2)\prime}(kr)}H_n^{(2)}(kr) Parameters ---------- N : int Maximum order. kr : (M,) array_like Wavenumber * radius. setup : {'open', 'card', 'rigid'} Array configuration (open, cardioids, rigid). Returns ------- bn : (M, 2*N+1) numpy.ndarray Radial weights for all orders up to N and the given wavenumbers. """ kr = util.asarray_1d(kr) n = np.arange(N+1) Bns = np.zeros((len(kr), N+1), dtype=complex) for i, x in enumerate(kr): Jn = special.jv(n, x) if setup == 'open': bn = Jn elif setup == 'card': bn = Jn - 1j * special.jvp(n, x, n=1) elif setup == 'rigid': Jnd = special.jvp(n, x, n=1) Hn = special.hankel2(n, x) Hnd = special.h2vp(n, x) bn = Jn - Jnd/Hnd*Hn else: raise ValueError('setup must be either: open, card or rigid') Bns[i, :] = bn Bns = np.concatenate((Bns, (Bns*(-1)**np.arange(N+1))[:, :0:-1]), axis=-1) return np.squeeze(Bns)