コード例 #1
0
ファイル: test_orthogonal.py プロジェクト: alchemyst/scipy
def test_roots_chebyu():
    weightf = orth.chebyu(5).weight_func
    verify_gauss_quad(sc.roots_chebyu, orth.eval_chebyu, weightf, -1., 1., 5)
    verify_gauss_quad(sc.roots_chebyu, orth.eval_chebyu, weightf, -1., 1., 25)
    verify_gauss_quad(sc.roots_chebyu, orth.eval_chebyu, weightf, -1., 1., 100)

    x, w = sc.roots_chebyu(5, False)
    y, v, m = sc.roots_chebyu(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_chebyu, 0)
    assert_raises(ValueError, sc.roots_chebyu, 3.3)
コード例 #2
0
def test_roots_chebyu():
    weightf = orth.chebyu(5).weight_func
    verify_gauss_quad(sc.roots_chebyu, sc.eval_chebyu, weightf, -1., 1., 5)
    verify_gauss_quad(sc.roots_chebyu, sc.eval_chebyu, weightf, -1., 1., 25)
    verify_gauss_quad(sc.roots_chebyu, sc.eval_chebyu, weightf, -1., 1., 100)

    x, w = sc.roots_chebyu(5, False)
    y, v, m = sc.roots_chebyu(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_chebyu, 0)
    assert_raises(ValueError, sc.roots_chebyu, 3.3)
コード例 #3
0
 def test_gausschebyshev2(self):
     """Test Gauss Chebyshev type 2 polynomial grid."""
     points, weights = roots_chebyu(10)
     grid = GaussChebyshevType2(10)
     weights /= np.sqrt(1 - np.power(points, 2))
     assert_allclose(grid.points, points)
     assert_allclose(grid.weights, weights)
コード例 #4
0
ファイル: onedgrid.py プロジェクト: theochem/grid
    def __init__(self, npoints: int):
        r"""Generate grid on :math:`[-1, 1]` interval based on Gauss-Chebyshev Type 2.

        Parameters
        ----------
        npoints : int
            Number of grid points.

        Returns
        -------
        OneDGrid
            A 1-D grid instance containing points and weights.

        """
        if npoints < 1:
            raise ValueError(
                f"Argument npoints must be an integer > 1, given {npoints}")
        # compute points and weights for Gauss-Chebyshev quadrature (Type 2)
        points, weights = roots_chebyu(npoints)
        weights /= np.sqrt(1 - np.power(points, 2))
        super().__init__(points, weights, (-1, 1))
コード例 #5
0
def GaussChebyshevType2(npoints):
    r"""Generate 1D grid on [-1, 1] interval based on Gauss-Chebyshev 2nd kind.

    The fundamental definition of Gauss-Chebyshev quadrature is:

    .. math::
        \int_{-1}^{1} \sqrt{1-x^2} f(x) dx \approx \sum_{i=1}^n w_i f(x_i)

    However, to integrate function :math:`g(x)` over [-1, 1], this is re-written as:

    .. math::
        \int_{-1}^{1}g(x) dx \approx \sum_{i=1}^n \frac{w_i}{\sqrt{1-x_i^2}} f(x_i)
        = \sum_{i=1}^n w_i' f(x_i)

    Where

    .. math::
        x_i = \cos\left( \frac{i}{n+1} \pi \right)

    and the weights

    .. math::
        w_i = \frac{\pi}{n+1} \sin^2 \left( \frac{i}{n+1} \pi \right)

    Parameters
    ----------
    npoints : int
        Number of grid points.

    Returns
    -------
    OneDGrid
        A 1D grid instance.

    """
    if npoints < 1:
        raise ValueError("npoints must be greater that one, given {npoints}")
    points, weights = roots_chebyu(npoints)
    weights /= np.sqrt(1 - np.power(points, 2))
    return OneDGrid(points, weights, (-1, 1))