Esempio n. 1
0
def test_roots_chebyt():
    weightf = orth.chebyt(5).weight_func
    verify_gauss_quad(sc.roots_chebyt, sc.eval_chebyt, weightf, -1., 1., 5)
    verify_gauss_quad(sc.roots_chebyt, sc.eval_chebyt, weightf, -1., 1., 25)
    verify_gauss_quad(sc.roots_chebyt, sc.eval_chebyt, weightf, -1., 1., 100, atol=1e-12)

    x, w = sc.roots_chebyt(5, False)
    y, v, m = sc.roots_chebyt(5, True)
    assert_allclose(x, y, 1e-14, 1e-14)
    assert_allclose(w, v, 1e-14, 1e-14)

    muI, muI_err = integrate.quad(weightf, -1, 1)
    assert_allclose(m, muI, rtol=muI_err)

    assert_raises(ValueError, sc.roots_chebyt, 0)
    assert_raises(ValueError, sc.roots_chebyt, 3.3)
Esempio n. 2
0
def test_roots_chebyt():
    weightf = orth.chebyt(5).weight_func
    verify_gauss_quad(sc.roots_chebyt, orth.eval_chebyt, weightf, -1., 1., 5)
    verify_gauss_quad(sc.roots_chebyt, orth.eval_chebyt, weightf, -1., 1., 25)
    verify_gauss_quad(sc.roots_chebyt, orth.eval_chebyt, weightf, -1., 1., 100)

    x, w = sc.roots_chebyt(5, False)
    y, v, m = sc.roots_chebyt(5, True)
    assert_allclose(x, y, 1e-14, 1e-14)
    assert_allclose(w, v, 1e-14, 1e-14)

    muI, muI_err = integrate.quad(weightf, -1, 1)
    assert_allclose(m, muI, rtol=muI_err)

    assert_raises(ValueError, sc.roots_chebyt, 0)
    assert_raises(ValueError, sc.roots_chebyt, 3.3)
Esempio n. 3
0
def gauss_chebyshev(n, lower=-1, upper=1):
    '''
    Gauss-Chebyshev quadrature:
    
    A rule of order 2*n-1 on the interval [-1, 1]
    with respect to the weight function w(x) = 1/sqrt(1-x**2).
    '''
    nodes, weights = special.roots_chebyt(n)
    if lower != -1 or upper != 1:
        nodes = (upper+lower)/2 + (upper-lower)/2*nodes
        weights = (upper-lower)/2*weights
    return nodes, weights
Esempio n. 4
0
def main_1():

    midpoint_rule(f, -1, 1, 1e-3)

    for n in (1, 2, 3, 4, 5, 6):  #в условии просят взять первые 6

        roots, weights = roots_legendre(n)
        print('Estimated: {}, number_of_the_roots: {}'.format(
            sum(weights * f(roots)), n))

    I_calculated_with_the_estimated_formula = abs(
        integrate.quad(f_2, -1, 1)[0])  #следует отметить
    # что в действительности без приближения интеграла от f,
    # значение будет равно примерно тому, что ниже (I_REAL), но мы его не используем:

    I_REAL = abs(integrate.quad(f, 0, 10)[0])

    print('Answer with estimation: {}, '
          'definite answer with scipy.integrate: {} '.format(
              I_calculated_with_the_estimated_formula, I_REAL))

    eps = 1e-10
    n = 1
    I = np.inf
    while eps < abs(I_calculated_with_the_estimated_formula - I):
        roots, weights = roots_legendre(n)
        I = sum(weights * f_2(roots))
        print('Estimated: {}, number_of_the_roots_on_Legendre: {}'.format(
            I, n))
        n += 1

    eps = 1e-10
    n = 1
    I_0 = np.inf
    I = 0
    checker = True

    while checker == True:
        roots, weights = roots_chebyt(n)
        I = sum(weights * f_3(roots))
        checker = abs(I_0 - I) != 0
        I_0 = I
        n += 1
    print('Estimated: {}, number_of_the_roots_on_Chebyshev: {}'.format(
        I, n - 1))
Esempio n. 5
0
 def _alphas_for_interpolation(self, interpolation, sample_points):
     sample_alphas = []
     if interpolation == 'equidistant':
         # print("Ip ed")
         # with 1/(2*section) distance to bodrders
         # sample_alphas = np.linspace(-1 + 1/(samples_per_section*2), 1 - 1/(2*samples_per_section), samples_per_section)
         sample_alphas = np.linspace(-1, 1, sample_points)
     elif interpolation == 'lobatto':
         # print("Ip lobatto")
         base_nodes, _ = self.g_c.gauss_lobatto(sample_points, 20)
         sample_alphas = [float(b_n) for b_n in base_nodes]
     elif interpolation == 'legendre':
         # print("Ip legendre")
         base_nodes, _ = self.g_c.gauss_legendre(sample_points, 20)
         sample_alphas = [float(b_n) for b_n in base_nodes]
     elif interpolation == 'chebychev':
         # print("Ip chebychev")
         base_nodes, _ = roots_chebyt(sample_points)
         sample_alphas = base_nodes
     return sample_alphas
Esempio n. 6
0
def test_chebyt_symmetry():
    x, w = sc.roots_chebyt(21)
    pos, neg = x[:10], x[11:]
    assert_equal(neg, -pos[::-1])
    assert_equal(x[10], 0)
Esempio n. 7
0
def test_chebyt_symmetry():
    x, w = sc.roots_chebyt(21)
    pos, neg = x[:10], x[11:]
    assert_equal(neg, -pos[::-1])
    assert_equal(x[10], 0)
Esempio n. 8
0
def max_rE_2d(ambisonic_order: int) -> float:
    """Maximum achievable |rE| with a uniform 2-D speaker array."""
    roots, _ = spec.roots_chebyt(ambisonic_order + 1)
    return roots.max()
Esempio n. 9
0
def GCheby_quad(f, n):
    # Integrates the function f from -1 to 1,
    # with weight function (1 - x**2)**(-1/2)
    xs, weights = roots_chebyt(n)
    fs = f(xs)
    return np.sum(fs * weights)