def raw_phi0(x, Z0): """Calculate \phi_0(x) for some array of x.""" n_x = n(x) # taylor expand n(z) about x to see that these are the correct # parameters to fill in the singularity near x: y0, m, k = -dndx(x), -d2ndx2(x)/2.0, -d3ndx3(x)/6.0 def integrand(z): return (n(z) - n_x) / (x - z) if abs(x - z) > 1e-4 else \ y0 + m * (z - x) + k * (z - x) ** 2 return integrate.quad(integrand, -Z0, Z0)[0]
def phi(xs, Z): """Evaluate phi(x) on a numpy list. This uses invibro.phi.phi0_cache to interpolate values.""" Z0, x_bound = phi0_cache['Z0'], phi0_cache['xs'][0] c1 = pi ** 2 /6; c2 = 7 * pi ** 4 / 60.0 neg = lambda x: log((Z - x) / (Z + x)) interp = lambda x: phi0_cache['interp'](x) + log((Z + x) / (Z0 + x)) large = lambda x: log(1 + Z / x) + c1 / x ** 2 + c2 / x ** 4 return ( piecewise(xs, [xs < 0], [neg, 0.0]) + piecewise(abs(xs), [abs(xs) < x_bound], [interp, large]) + complex(0, -0.5) * n(xs) )
def integrand(z): return (n(z) - n_x) / (x - z) if abs(x - z) > 1e-4 else \ y0 + m * (z - x) + k * (z - x) ** 2