[Scipy-svn] r6287 - trunk/scipy/integrate/tests
scipy-svn at scipy.org
scipy-svn at scipy.org
Tue Mar 30 23:04:22 EDT 2010
Author: warren.weckesser
Date: 2010-03-30 22:04:22 -0500 (Tue, 30 Mar 2010)
New Revision: 6287
Modified:
trunk/scipy/integrate/tests/test_quadrature.py
Log:
Add a test for scipy.integrate.newton_cotes. A more comprehensive set of tests would be better, but it's a start.
Modified: trunk/scipy/integrate/tests/test_quadrature.py
===================================================================
--- trunk/scipy/integrate/tests/test_quadrature.py 2010-03-31 01:42:00 UTC (rev 6286)
+++ trunk/scipy/integrate/tests/test_quadrature.py 2010-03-31 03:04:22 UTC (rev 6287)
@@ -3,7 +3,7 @@
from numpy import cos, sin, pi
from numpy.testing import *
-from scipy.integrate import quadrature, romberg, romb
+from scipy.integrate import quadrature, romberg, romb, newton_cotes
class TestQuadrature(TestCase):
def quad(self, x, a, b, args):
@@ -35,6 +35,28 @@
expected_val = 0.45969769413185085
assert_almost_equal(valmath, expected_val, decimal=7)
+ def test_newton_cotes(self):
+ """Test the first few degrees, for evenly spaced points."""
+ n = 1
+ wts, errcoff = newton_cotes(n, 1)
+ assert_equal(wts, n*numpy.array([0.5, 0.5]))
+ assert_almost_equal(errcoff, -n**3/12.0)
+ n = 2
+ wts, errcoff = newton_cotes(n, 1)
+ assert_almost_equal(wts, n*numpy.array([1.0, 4.0, 1.0])/6.0)
+ assert_almost_equal(errcoff, -n**5/2880.0)
+
+ n = 3
+ wts, errcoff = newton_cotes(n, 1)
+ assert_almost_equal(wts, n*numpy.array([1.0, 3.0, 3.0, 1.0])/8.0)
+ assert_almost_equal(errcoff, -n**5/6480.0)
+
+ n = 4
+ wts, errcoff = newton_cotes(n, 1)
+ assert_almost_equal(wts, n*numpy.array([7.0, 32.0, 12.0, 32.0, 7.0])/90.0)
+ assert_almost_equal(errcoff, -n**7/1935360.0)
+
+
if __name__ == "__main__":
run_module_suite()
More information about the Scipy-svn
mailing list