Example #1
0
def do_plot(is_h=True):
    from scipy.special._ufuncs import (_struve_power_series,
                                       _struve_asymp_large_z,
                                       _struve_bessel_series)

    vs = np.linspace(-1000, 1000, 91)
    zs = np.sort(np.r_[1e-5, 1.0, np.linspace(0, 700, 91)[1:]])

    rp = _struve_power_series(vs[:,None], zs[None,:], is_h)
    ra = _struve_asymp_large_z(vs[:,None], zs[None,:], is_h)
    rb = _struve_bessel_series(vs[:,None], zs[None,:], is_h)

    mpmath.mp.dps = 50
    if is_h:
        sh = lambda v, z: float(mpmath.struveh(mpmath.mpf(v), mpmath.mpf(z)))
    else:
        sh = lambda v, z: float(mpmath.struvel(mpmath.mpf(v), mpmath.mpf(z)))
    ex = np.vectorize(sh, otypes='d')(vs[:,None], zs[None,:])

    err_a = err_metric(ra[0], ex) + 1e-300
    err_p = err_metric(rp[0], ex) + 1e-300
    err_b = err_metric(rb[0], ex) + 1e-300

    err_est_a = abs(ra[1]/ra[0])
    err_est_p = abs(rp[1]/rp[0])
    err_est_b = abs(rb[1]/rb[0])

    z_cutoff = 0.7*abs(vs) + 12

    levels = [-1000, -12]

    plt.cla()

    plt.hold(1)
    plt.contourf(vs, zs, np.log10(err_p).T, levels=levels, colors=['r', 'r'], alpha=0.1)
    plt.contourf(vs, zs, np.log10(err_a).T, levels=levels, colors=['b', 'b'], alpha=0.1)
    plt.contourf(vs, zs, np.log10(err_b).T, levels=levels, colors=['g', 'g'], alpha=0.1)

    plt.contour(vs, zs, np.log10(err_p).T, levels=levels, colors=['r', 'r'], linestyles=[':', ':'])
    plt.contour(vs, zs, np.log10(err_a).T, levels=levels, colors=['b', 'b'], linestyles=[':', ':'])
    plt.contour(vs, zs, np.log10(err_b).T, levels=levels, colors=['g', 'g'], linestyles=[':', ':'])

    lp = plt.contour(vs, zs, np.log10(err_est_p).T, levels=levels, colors=['r', 'r'], linestyles=['-', '-'])
    la = plt.contour(vs, zs, np.log10(err_est_a).T, levels=levels, colors=['b', 'b'], linestyles=['-', '-'])
    lb = plt.contour(vs, zs, np.log10(err_est_b).T, levels=levels, colors=['g', 'g'], linestyles=['-', '-'])

    plt.clabel(lp, fmt={-1000: 'P', -12: 'P'})
    plt.clabel(la, fmt={-1000: 'A', -12: 'A'})
    plt.clabel(lb, fmt={-1000: 'B', -12: 'B'})

    plt.plot(vs, z_cutoff, 'k--')

    plt.xlim(vs.min(), vs.max())
    plt.ylim(zs.min(), zs.max())

    plt.xlabel('v')
    plt.ylabel('z')
Example #2
0
def make_struve_h_vals():
    from mpmath import struveh

    nu = [mpf('0.5'), mpf('1.25'), mpf('1.5'), mpf('1.75'), mpf(2), mpf('2.75')]
    x = [mpf('0.2'), mpf(1), mpf(2), mpf('2.5'), mpf(3), mpf(5), mpf(10)]

    nu, x = zip(*outer(nu, x))
    h = [struveh(*vals) for vals in zip(nu, x)]

    return make_special_vals('struve_h_vals', ('nu', nu), ('x', x), ('h', h))
Example #3
0
def make_struve_h_vals():
    from mpmath import struveh

    nu = [mpf('0.5'), mpf('1.25'), mpf('1.5'), mpf('1.75'), mpf(2), mpf('2.75')]
    x = [mpf('0.2'), mpf(1), mpf(2), mpf('2.5'), mpf(3), mpf(5), mpf(10)]

    nu, x = zip(*outer(nu, x))
    h = [struveh(*vals) for vals in zip(nu, x)]

    return make_special_vals('struve_h_vals', ('nu', nu), ('x', x), ('h', h))
Example #4
0
 def test_struve(self):
     assert_mpmath_equal(sc.struve,
                         _exception_to_nan(lambda v, x: mpmath.struveh(v, x, **HYPERKW)),
                         [Arg(-1e30, 1e30), Arg()],
                         n=2000)
Example #5
0
 def test_struve(self):
     assert_mpmath_equal(
         sc.struve,
         _exception_to_nan(lambda v, x: mpmath.struveh(v, x, **HYPERKW)),
         [Arg(-1e30, 1e30), Arg()],
         n=2000)