def exact(k, R1, R2, derivs): if (derivs): # Bessel evaluated at R1 J0_1 = special.j0(k * R1) Y0_1 = special.y0(k * R1) J1_1 = special.j1(k * R1) Y1_1 = special.y1(k * R1) # Bessel evaluated at R2 J0_2 = special.j0(k * R2) Y0_2 = special.y0(k * R2) J1_2 = special.j1(k * R2) Y1_2 = special.y1(k * R2) # # d Z1(k r)/dr = k*Z0(k r) - Z1(k r) / r # Jprime_1 = k * J0_1 - J1_1 / R1 Jprime_2 = k * J0_2 - J1_2 / R2 Yprime_1 = k * Y0_1 - Y1_1 / R1 Yprime_2 = k * Y0_2 - Y1_2 / R2 else: Jprime_1 = special.jvp(1, k * R1, 1) Jprime_2 = special.jvp(1, k * R2, 1) Yprime_1 = special.yvp(1, k * R1, 1) Yprime_2 = special.yvp(1, k * R2, 1) # F(k r) = J'_m(kr R1) * Y'_m(kr R2) - J'_m(kr R2) * Y'_m(kr R1) = 0 return Jprime_1 * Yprime_2 - Jprime_2 * Yprime_1
def tetmConstants(self, ri, ro, neff, wl, EH, c, idx): a = numpy.empty((2, 2)) n = self.maxIndex(wl) u = self.u(ro, neff, wl) urp = self.u(ri, neff, wl) if neff < n: B1 = j0(u) B2 = y0(u) F1 = j0(urp) / B1 F2 = y0(urp) / B2 F3 = -j1(urp) / B1 F4 = -y1(urp) / B2 c1 = wl.k0 * ro / u else: B1 = i0(u) B2 = k0(u) F1 = i0(urp) / B1 F2 = k0(urp) / B2 F3 = i1(urp) / B1 F4 = -k1(urp) / B2 c1 = -wl.k0 * ro / u c3 = c * c1 a[0, 0] = F1 a[0, 1] = F2 a[1, 0] = F3 * c3 a[1, 1] = F4 * c3 return numpy.linalg.solve(a, EH.take(idx))
def cutoffTE(b): # EXP: 2.4220557071361126 a = rho * b return (i0(u1 * a) * (j0(u2 * b) * yn(2, u2 * a) - y0(u2 * b) * jn(2, u2 * a)) - iv(2, u1 * a) * (j0(u2 * a) * y0(u2 * b) - y0(u2 * a) * j0(u2 * b)))
def cutoffTM(b): # EXP: 2.604335468618898 a = rho * b return (n22 / n12 * (j0(u2 * b) * yn(2, u2 * a) - y0(u2 * b) * jn(2, u2 * a)) + (n22 / n12 - 1 + iv(2, u1 * a) / i0(u1 * a)) * (j0(u2 * b) * y0(u2 * a) - y0(u2 * b) * j0(u2 * a)))
def g_int_lamarche(x, tt, Rt, rt, kt, gam, v): # tt = Fourier number # re = outer radius of the equivalent tube for concentric cylinders # rb = borehole radius # ks = soil thermal conductivity # kg = grout thermal conductivity # als = soil thermal diffusivity # alg = grout thermal diffusivity zeta1 = (1 - v * Rt * x**2) * y1(x) - v * x * y0(x) zeta2 = (1 - v * Rt * x**2) * j1(x) - v * x * j0(x) psi = (zeta2 * (j0(x * rt * gam) * y1(x * rt) - j1(x * rt * gam) * y0(x * rt) * kt * gam) - zeta1 * (j0(x * rt * gam) * j1(x * rt) - j1(x * rt * gam) * j0(x * rt) * kt * gam)) phi = (zeta1 * (y0(x * rt * gam) * j1(x * rt) - y1(x * rt * gam) * j0(x * rt) * kt * gam) - zeta2 * (y0(x * rt * gam) * y1(x * rt) - y1(x * rt * gam) * y0(x * rt) * kt * gam)) I = (1 - exp(-x**2 * tt)) / (x**5 * (phi**2 + psi**2)) return I
def _tecoeq(self, v0, nu): u1r1, u2r1, u2r2, s1, s2, n1sq, n2sq, n3sq = self.__params(v0) (f11a, f11b) = ((j0(u1r1), jn(2, u1r1)) if s1 > 0 else (i0(u1r1), -iv(2, u1r1))) if s2 > 0: f22a, f22b = j0(u2r2), y0(u2r2) f2a = jn(2, u2r1) * f22b - yn(2, u2r1) * f22a f2b = j0(u2r1) * f22b - y0(u2r1) * f22a else: # a f22a, f22b = i0(u2r2), k0(u2r2) f2a = kn(2, u2r1) * f22a - iv(2, u2r1) * f22b f2b = i0(u2r1) * f22b - k0(u2r1) * f22a return f11a * f2a - f11b * f2b
def tau_binf (a, c): # numerator : integrand = lambda x, a,c: (1-np.exp(-x**2/(4*a**2*c**2))) / x**3 * (ss.y0(x/a)*ss.j0(x)-ss.j0(x/a)*ss.y0(x)) / (ss.y0(x)**2+ss.j0(x)**2) - log(1/a)/(2*a**2*c**2*π) / (1 + 4/π**2 * (np.euler_gamma+np.log(x/2))**2) / x # |------------------- g1 -------------------------------------------------------------------------------------| |-------------------------- g2 -----------------------------------------| cutoff = 100*max(1,c) I = sint.quad( integrand, 0, cutoff, args=(a,c), epsrel=1e-5, limit=1000 )[0] int_num = I + log(1/a)*int_2_rem(cutoff)/(4*a**2*c**2) # denominator : integrand = lambda x, a,c: ( np.exp(-x**2/(4*a**2*c**2)) * (ss.y0(x/a)*ss.j0(x)-ss.j0(x/a)*ss.y0(x)) / (ss.y0(x)**2+ss.j0(x)**2) - 2/π * log(1/a) / (1 + 4/π**2 * (np.euler_gamma+np.log(x/2))**2) ) / x # |----------------- f1 ----------------------------------------------------------------------------| |-------------------------- f2 -------------------------------| cutoff = max(10,2*c**2) I = sint.quad( integrand, 0, cutoff, args=(a,c), epsrel=1e-7, limit=1000 )[0] den = 1 - 2/π * (I + log(1/a)*int_2_rem(cutoff)) return 8*a**2/π * int_num / den
def gendata(X): l = '%5s%23s%23s%23s%23s%23s%23s\n' % ('x', 'J0', 'J1', 'J2', 'Y0', 'Y1', 'Y2') for i, x in enumerate(X): l += '%5.2f%23.15e%23.15e%23.15e%23.15e%23.15e%23.15e\n' % (x, sp.j0( x), sp.j1(x), sp.jv(2, x), sp.y0(x), sp.y1(x), sp.yn(2, x)) return l
def E(self, x, y, z, t): w = self.pulsation k = self.wavenum r = (x**2 + y**2)**0.5 ez = 0.5*spec.j0(k*r)*np.cos(w*t) + \ 0.5*spec.y0(k*(r-0.1))*np.sin(w*t) return 0, 0, ez
def plotrcfte(): V = numpy.linspace(1, 7) rho = 0.5 f = j0(V) * yn(2, V*rho) - y0(V) * jn(2, rho*V) pyplot.plot(V, f) pyplot.show()
def plotrcfte(): V = numpy.linspace(1, 7) rho = 0.5 f = j0(V) * yn(2, V * rho) - y0(V) * jn(2, rho * V) pyplot.plot(V, f) pyplot.show()
def _tmcoeq(self, v0, nu): u1r1, u2r1, u2r2, s1, s2, n1sq, n2sq, n3sq = self.__params(v0) if s1 == 0: # e f11a, f11b = 2, 1 elif s1 > 0: # a, b, d f11a, f11b = j0(u1r1) * u1r1, j1(u1r1) else: # c f11a, f11b = i0(u1r1) * u1r1, i1(u1r1) if s2 > 0: f22a, f22b = j0(u2r2), y0(u2r2) f2a = j1(u2r1) * f22b - y1(u2r1) * f22a f2b = j0(u2r1) * f22b - y0(u2r1) * f22a else: # a f22a, f22b = i0(u2r2), k0(u2r2) f2a = i1(u2r1) * f22b + k1(u2r1) * f22a f2b = i0(u2r1) * f22b - k0(u2r1) * f22a return f11a * n2sq * f2a - f11b * n1sq * f2b * u2r1
def test_bessely_larger(self, dtype): x = np.random.uniform(1., 30., size=int(1e4)).astype(dtype) try: from scipy import special # pylint: disable=g-import-not-at-top self.assertAllClose( special.y0(x), self.evaluate(special_math_ops.bessel_y0(x))) self.assertAllClose( special.y1(x), self.evaluate(special_math_ops.bessel_y1(x))) except ImportError as e: tf_logging.warn('Cannot test special functions: %s' % str(e))
def _z(self, omega): f = omega / (2. * np.pi) return np.sqrt(2. * self.c0 / self.h) \ * (1j * special.j0(4. * np.pi * f / self.alpha * np.sqrt(2. / (self.h * self.c0))) + special.y0(4. * np.pi * f / self.alpha * np.sqrt(2 / (self.h * self.c0)))) \ / (special.j1(4. * np.pi * f / self.alpha * np.sqrt(2. / (self.h * self.c0))) - 1j * special.y1(4. * np.pi * f / self.alpha * np.sqrt(2. / (self.h * self.c0))))
def keldysh_interaction(radius, radius_0, ep12): """ Keldysh Interaction. :param radius: Distance from centre :param radius_0: Scale distance corresponding to inherent screening. :param ep12: average of top and bottome dielectric constants. :return: interaction """ term_arg = (radius / radius_0) * ep12 struve_term = spec.struve(0, term_arg) bessel_term = spec.y0(term_arg) interaction = keldysh_prefactor / radius_0 * (struve_term - bessel_term) return interaction
def gentable(X): # header l = '%5s %18s %13s %13s %13s %13s %13s\n' % ( 'x', 'J0(x)', 'J1(x)', 'J2(x)', 'Y0(x)', 'Y1(x)', 'Y2(x)') # table for i, x in enumerate(X): l += '%5.2f %18.15f %13.10f %13.10f %13.10f %13.10f %13.10f\n' % ( x, sp.j0(x), sp.j1(x), sp.jv(2, x), sp.y0(x), sp.y1(x), sp.yn( 2, x)) if (i + 1) % 5 == 0: l += '\n' return l
def fpt_2d_free_survival (R, t, D, Rtol, σ, regularize=True, split_domain=True): if σ == 0: a = Rtol/R c = R/np.sqrt(4*D*t) f = lambda x, a,c: np.exp(-x**2/(4*a**2*c**2)) / x * (ss.y0(x/a)*ss.j0(x)-ss.j0(x/a)*ss.y0(x)) / (ss.y0(x)**2+ss.j0(x)**2) if regularize: # regularization of the divergence of f at x=0 by substracting the leading-order term, # which is, amazingly, integrable analytically; this allows the integrator to better behave; # splitting the domain in two does improve the result a tiny bit; # (but this method seems to lead to a slight overestimation of the survival proba, if the langevin simulations are accurate) f_reg = lambda x, a,c: f(x,a,c) - 1/x * 2/π * log(1/a) / (1 + 4/π**2 * (np.euler_gamma+np.log(x/2))**2) if split_domain: ps0 = lambda a,c: 2*log(1/a) + 2/π * ( sint.quad(f_reg, 0, 1, args=(a,c), epsabs=1e-6, limit=1000)[0] + sint.quad(f_reg, 1, +np.inf, args=(a,c), epsabs=1e-5, limit=1000)[0] ) else: ps0 = lambda a,c: 2*log(1/a) + 2/π * ( sint.quad(f_reg, 0, +np.inf, args=(a,c), epsabs=1e-5, limit=1000)[0] ) else: # splitting the domain in two (one near zero where there is a singularity, the other to infinity) # allows to use to integration methods, one on the finite domain which treats the singularity well # and the other which treats the rest of the infinite domain without singularity if split_domain: ps0 = lambda a,c: 2/π * ( sint.quad(f, 0, 0.1, args=(a,c), epsabs=1e-4, limit=1000)[0] + sint.quad(f, 0.1, +np.inf, args=(a,c), epsabs=1e-6, limit=1000)[0] ) else: ps0 = lambda a,c: 2/π * sint.quad(f, 0, +np.inf, args=(a,c), epsabs=1e-5, limit=1000)[0] return np.vectorize( lambda a,c: (ps0(a,c) if a < 0.999 else 0.) )(a,c) else: # just a convolution of a guassian with the σ=0 curve pass
def h0(s): return j0(s) + 1j * y0(s)
def new_func(x): if isinstance(x, np.ndarray): dtype = type(F(1)) sel = x > 1e-10 out = np.zeros(x.shape, dtype=dtype) out[sel] = F(x[sel]) else: out = 0.0 if x < 1e-10 else F(x) return out return new_func H0 = FG(lambda x: struve( 0, x), 1e-10, 10) H1 = FG(lambda x: struve(-1, x), 1e-10, 10) H2 = FG(lambda x: struve(-2, x), 1e-10, 10) H3 = FG(lambda x: struve(-3, x), 1e-10, 10) Y0 = FG(lambda x: y0(x), 1e-10, 10) Y1 = FG(lambda x: yn(1, x), 1e-10, 10) Y2 = FG(lambda x: yn(2, x), 1e-10, 10) """ Test how to do biharmonic FMM using cloud of points... """ def random3(N): a1 = np.random.rand(N)-0.5 a2 = np.random.rand(N)-0.5 a3 = np.random.rand(N)-0.5 return a1, a2, a3 # number of points to compute for N = 100
def fdbf(shotGather, weightType='none', steeringVector='plane', numv=2048, min_vel=1, max_vel=1000, min_frequency=5, max_frequency=100): # Ensure that min_velocity is greater than zero for numerical stability if min_vel < 1: min_vel = 1 # Spatiospectral correlation matrix......................................... R = np.zeros(((shotGather.n_samples / 2 + 1), shotGather.n_channels, shotGather.n_channels), complex) for m in range(shotGather.n_channels): for n in range(shotGather.n_channels): freq, R[:, m, n] = signal.csd(shotGather.timeHistories[:, m], shotGather.timeHistories[:, n], fs=1.0 / shotGather.dt, window='boxcar', nperseg=shotGather.n_samples) # Remove frequencies above/below specificied max/min frequencies and downsample (if required by zero padding) fminID = np.argmin(np.absolute(freq - min_frequency)) fmaxID = np.argmin(np.absolute(freq - max_frequency)) freq_id = range(fminID, (fmaxID + 1), shotGather.multiple) R = R[freq_id, :, :] freq = freq[freq_id] # Weighting matrices........................................................ W = np.zeros(np.shape(R)) # Sqare root of distance from source if str.lower(weightType) == 'sqrt': W[:, :, :] = np.diag( np.sqrt(abs(shotGather.offset) + shotGather.position)) # 1/|A(f,x)|, where A is Fourier Transform of a(t,x) elif str.lower(weightType) == 'invamp': freqFFT = np.concatenate([ np.arange(0, shotGather.fnyq + shotGather.df, shotGather.df), np.arange(-(shotGather.fnyq - shotGather.df), 0, shotGather.df) ]) Af = np.fft.fft(shotGather.timeHistories, axis=0) for bb in range(len(freq)): freq_id = np.argmin(np.absolute(freqFFT - freq[bb])) weight = 1.0 / np.absolute(Af[freq_id, :]) W[bb, :, :] = np.diag(weight) # No weighting else: W[:, :, :] = np.eye(shotGather.n_channels) # Beamforming............................................................... v_vals = np.linspace(min_vel, max_vel, numv) # Pre-allocate variables for efficiency power = np.zeros((numv, len(freq)), complex) pnorm = np.zeros(np.shape(power), complex) v_peak = np.zeros(np.shape(freq)) # Loop through all frequency values, compute power at all trial wavenumbers for m in range(len(freq)): # Convert trial velocities to wavenumbers (set equal to 0 for k > kres) k_vals = 2 * np.pi * freq[m] / v_vals alias_id = np.where(k_vals > shotGather.kres)[0] # Weighting matrix for current frequency Wf = W[m, :, :] for k in range(numv): # Steering vector if str.lower(steeringVector) == 'cylindrical': pos = shotGather.position # If x[0]=0, set equal to arbitrarilly small number for stability if pos[0] == 0: pos[0] = 1e-16 H0 = special.j0( k_vals[k] * pos) + 1j * special.y0(k_vals[k] * pos) expterm = np.exp(1j * np.angle(H0)) else: expterm = np.exp(1j * k_vals[k] * shotGather.position) # power[k,m] = expterm' * Wf * R[m,:,:] * Wf' * expterm power[k, m] = np.dot( np.dot( np.dot(np.dot(np.conj(expterm).transpose(), Wf), R[m, :, :]), Wf.transpose()), expterm) power[alias_id, m] = 0 # Index of wavenumber corresponding to maximum power at freq[m] max_id = np.argmax(np.abs(power[:, m])) # Normalize all power values at freq[m] by the maximum power at freq[m] pnorm[:, m] = np.abs(power[:, m]) / np.max(np.abs(power[:, m])) pnorm[alias_id, m] = float('nan') # Wavenumber corresponding to max power at freq[m] v_peak[m] = v_vals[max_id] # Create instance of DispersionPower class dispersionPower = dctypes.DispersionPower(freq, v_peak, v_vals, 'velocity', shotGather.kres, pnorm) return dispersionPower
def green2d(k, r): ''' Evaluate the 2-D Green's function for a distance r and wave number k. ''' return 0.25j * (spec.j0(k * r) + 1j * spec.y0(k * r))
def true_func(x): return struve(0, x) - y0(x)
def _hankel2_0(x): """Wrapper for Hankel function of the second type using fast versions of the Bessel functions of first/second kind in scipy""" return special.j0(x)-1j*special.y0(x)
def cutoffTE(b): # EXP: 2.4220557071361126 a = rho * b return (i0(u1*a) * (j0(u2*b) * yn(2, u2*a) - y0(u2*b) * jn(2, u2*a)) - iv(2, u1*a) * (j0(u2*a) * y0(u2*b) - y0(u2*a) * j0(u2*b)))
def Y0(s): """ Returns the value of the bessel funciton of the first kind in s """ if s<0.001: s=0.001 # Y0(0)=-inf return sp.y0(s)
def base_gf(x): Y = y0(x) H = struve(0, x) return 0.25 * (H - Y)
def _CHS(u, Fo, p): CHS_integrand = 1./(u**2*pi**2)*(np.exp(-u**2*Fo) - 1.0) / (j1(u)**2 + y1(u)**2) * (j0(p*u)*y1(u) - j1(u)*y0(p*2)) return CHS_integrand
#------------------------------------------------------------------------------ # Evaluerer sylindersluk-løsningen #------------------------------------------------------------------------------ Fo = np.zeros(n) # Fourier-tallet G = np.zeros(s) # Sylindersluk-funksjonen T_b_uss = np.zeros(s) # Temperatur ved borehullveggen for uss løsningen for i in range(n): # Fouriertallet Fo[i] = (a_g/(r_b**2))*tid[i] # Beregner integralet i sylindersluk-funksjonen G[i] = integrate.quad(lambda h:((np.exp(-(h**2)*Fo[i]))-1)*((sp.j0(h)*sp.y1(h) - sp.y0(h)*sp.j1(h))/((h**2)*((sp.j1(h)**2)+(sp.y1(h)**2)))),0,m.inf) # Temperatur ved borehullveggen T_b_uss[i] = T_g + q/(k_g*(np.pi**2))*G[i] #------------------------------------------------------------------------------ # Temperaturprofilen ved borehullveggen for de ulike modellene #------------------------------------------------------------------------------ line1, = ax1.plot(tid_skala, T_b_pyg,'k-', lw=1.5, label='Pygfunction' ) line2, = ax1.plot(tid_skala, T_b_uls[:,0], 'r-', lw=1.5, label='u_linjesluk') line3, = ax1.plot(tid_skala, T_b_uss[:,0], 'y-', lw=1.5, label='u_sylindersluk') plt.legend(handler_map={line3: HandlerLine2D(numpoints=4)}, loc=4)
def phi(lam, r): phir = (j0(lam * r) * y1(lam)) - (j1(lam) * y0(lam * r)) return phir
from function_generator import standard_error_model, relative_error_model, new_error_model import time from scipy.special import k0, struve, y0, hankel1 import numba n = 1000 * 1000 * 10 approx_range = [1e-10, 1000] test_range = [1e-10, 999] tol = 1e-14 order = 8 # functions to test evaluation of true_funcs = [ lambda x: k0(0.1 * x), lambda x: k0(0.1 * x), lambda x: y0(x), lambda x: hankel1(0, x), lambda x: np.log(x), lambda x: 1 / x**8, lambda x: 1 / np.sqrt(x), lambda x: x * x, lambda x: np.sin(1 / x), ] true_func_disp = [ 'k0(x/10); Using relative error model, relative error should be good', 'k0(x/10); Using standard error model, relative error not guaranteed', 'y0(x); Using standard error model, relative error not guaranteed', 'hankel1(0, x); Using standard error model, relative error not guaranteed', 'np.log(x); Using standard error model, relative error not guaranteed', '1/x**8; Using relative error model, relative error should be good', '1/sqrt(x) Using relative error model, relative error should be good',
def djv_dv(x): return pi / 2 * spec.y0(x)
def cutoffTM(b): # EXP: 2.604335468618898 a = rho * b return (n22 / n12 * (j0(u2*b) * yn(2, u2*a) - y0(u2*b) * jn(2, u2*a)) + (n22 / n12 - 1 + iv(2, u1*a) / i0(u1*a)) * (j0(u2*b) * y0(u2*a) - y0(u2*b) * j0(u2*a)))
b = 0.5 * P['C'] a = -1.0 w = 2. * np.pi * P['F'] t = np.asarray(P['T']) RHO = P['RHO'] U = np.absolute(P['V0']) THETA_MAX = P['THETA_MAX'] HEAVE_MAX = P ['HEAVE_MAX'] PHI = P['PHI'] k = w * b / np.absolute(P['V0']) k2 = np.pi * P['F'] * P['C'] / np.absolute(P['V0']) St = 2. * P['F'] * P['HEAVE_MAX'] / np.absolute(P['V0']) F = (j1(k)*(j1(k)+y0(k)) + y1(k)*(y1(k)-j0(k))) / ((j1(k)+y0(k))**2 + (y1(k)-j0(k))**2) G = -(y1(k)*y0(k) + j1(k)*j0(k)) / ((j1(k)+y0(k))**2 + (y1(k)-j0(k))**2) L = -RHO * b**2 * (U * np.pi * THETA_MAX * w * np.cos(w * t + PHI) - np.pi * HEAVE_MAX * w**2 * np.sin(w * t) + np.pi * b * a * THETA_MAX * w**2 * np.sin(w * t + PHI)) - 2. * np.pi * RHO * U * b * F * (U * THETA_MAX * np.sin(w * t + PHI) + HEAVE_MAX * w * np.cos(w * t) + b * (0.5 - a) * THETA_MAX * w * np.cos(w * t + PHI)) - 2. * np.pi * RHO * U * b * G * (U * THETA_MAX * np.cos(w * t + PHI) - HEAVE_MAX * w * np.sin(w * t) - b * (0.5 - a) * THETA_MAX * w * np.sin(w * t + PHI)) Cl = np.real(L) / (0.5 * P['RHO'] * np.absolute(P['V0'])**2 * P['C']) execfile("rigid_bem2d.py") expCsv = np.genfromtxt('forces.csv', delimiter=',') #P['SW_KUTTA'] = True # #execfile("rigid_bem2d_kutta.py") #impCsv = np.genfromtxt('forces.csv', delimiter=',') #Determine Error
def g_int(x, Fo, rt): num = exp(-Fo * x**2) - 1 den = x**2 * (j1(x)**2 + y1(x)**2) I = num / den * (j0(rt * x) * y1(x) - y0(rt * x) * j1(x)) return I
def tau_b (a, b, c): A1 = lambda a,b: sint.quad( lambda z, a,b: z * exp(-b**2/2-z**2/2) * ss.i0(b*z) * log(z/a/b), a*b, 10+b, args=(a,b), epsrel=1e-10, limit=1000 )[0] # numerator : integrand = lambda z,x, a,b,c: z * exp(-b**2/2-z**2/2) * ss.i0(b*z) * ( (1-exp(-x**2/(4*a**2*c**2)))/x**3 * (ss.y0(x*z/a/b)*ss.j0(x)-ss.j0(x*z/a/b)*ss.y0(x)) / (ss.y0(x)**2+ss.j0(x)**2) - log(z/a/b)/(2*a**2*c**2*π) / (1 + 4/π**2 * (np.euler_gamma+log(x/2))**2) / x ) cutoff = 100*max(1,c) I = sint.dblquad( integrand, 0, cutoff, lambda x:a*b, lambda x:10+b, args=(a,b,c), epsrel=1e-8 )[0] int_num = I + A1(a,b)*int_2_rem(cutoff)/(4*a**2*c**2) # denominator : integrand = lambda z,x, a,b,c: z * exp(-b**2/2-z**2/2) * ss.i0(b*z) * ( exp(-x**2/(4*a**2*c**2)) / x * (ss.y0(x*z/a/b)*ss.j0(x)-ss.j0(x*z/a/b)*ss.y0(x)) / (ss.y0(x)**2+ss.j0(x)**2) - log(z/a/b) * 2/π / (1 + 4/π**2 * (np.euler_gamma+log(x/2))**2) / x ) cutoff = max(10,2*c**2) I = sint.dblquad( integrand, 0, cutoff, lambda z:a*b, lambda z:10+b, args=(a,b,c), epsrel=1e-8 )[0] den = 1 - 2/π*(I + A1(a,b)*int_2_rem(cutoff)) # F1 = lambda a,b,x: exp(-b**2/2) * sint.quad(lambda z,a,b,x: z * exp(-z**2/2) * ss.y0(x*z/a/b) * ss.i0(b*z), a*b, 10+b, args=(a,b,x), epsrel=1e-8, limit=10000)[0] # F2 = lambda a,b,x: exp(-b**2/2) * sint.quad(lambda z,a,b,x: z * exp(-z**2/2) * ss.j0(x*z/a/b) * ss.i0(b*z), a*b, 10+b, args=(a,b,x), epsrel=1e-8, limit=10000)[0] # integrand = lambda x, a,b,c: exp(-x**2/(4*a**2*c**2))/x * ( F1(a,b,x)*ss.j0(x) - F2(a,b,x)*ss.y0(x) ) / ( ss.j0(x)**2 + ss.y0(x)**2 ) # den = 1 - 2/π*sint.quad( integrand, 0, cutoff, args=(a,b,c), epsrel=1e-5, limit=200 )[0] return 8*a**2/π * int_num / den