Пример #1
0
 def test_errors_raise(self):
     """Test errors raise."""
     with self.assertRaises(ValueError):
         GaussLaguerre(10, -1)
     with self.assertRaises(ValueError):
         GaussLaguerre(0, 1)
     with self.assertRaises(ValueError):
         GaussLegendre(-10)
     with self.assertRaises(ValueError):
         GaussChebyshev(-10)
     with self.assertRaises(ValueError):
         HortonLinear(-10)
     with self.assertRaises(ValueError):
         TanhSinh(10, 1)
     with self.assertRaises(ValueError):
         Simpson(4)
     with self.assertRaises(ValueError):
         GaussChebyshevType2(-10)
     with self.assertRaises(ValueError):
         GaussChebyshevLobatto(-10)
     with self.assertRaises(ValueError):
         Trapezoidal(-10)
     with self.assertRaises(ValueError):
         RectangleRuleSineEndPoints(-10)
     with self.assertRaises(ValueError):
         RectangleRuleSine(-10)
     with self.assertRaises(ValueError):
         TanhSinh(-11, 1)
     with self.assertRaises(ValueError):
         Simpson(-11)
     with self.assertRaises(ValueError):
         MidPoint(-10)
     with self.assertRaises(ValueError):
         ClenshawCurtis(-10)
     with self.assertRaises(ValueError):
         FejerFirst(-10)
     with self.assertRaises(ValueError):
         FejerSecond(-10)
Пример #2
0
    def test_ClenshawCurtis(self):
        """Test for ClenshawCurtis."""
        grid = ClenshawCurtis(10)
        points = np.zeros(10)
        weights = 2 * np.ones(10)

        theta = np.zeros(10)

        for i in range(0, 10):
            theta[i] = (9 - i) * np.pi / 9

        points = np.cos(theta)
        weights = np.zeros(10)

        jmed = 9 // 2

        for i in range(0, 10):
            weights[i] = 1

            for j in range(0, jmed):
                if (2 * (j + 1)) == 9:
                    b = 1
                else:
                    b = 2

                weights[i] = weights[i] - b * np.cos(2 * (j + 1) * theta[i]) / (
                    4 * j * (j + 2) + 3
                )

        for i in range(1, 9):
            weights[i] = 2 * weights[i] / 9

        weights[0] /= 9
        weights[9] /= 9

        assert_allclose(grid.points, points)
        assert_allclose(grid.weights, weights)