Merge pull request #537 from tminka/quad
QuadratureRule.summation adds the error across intervals
This commit is contained in:
@@ -55,3 +55,6 @@ mpmath.egg-info/
|
||||
# Coverage-related files
|
||||
.coverage
|
||||
htmlcov/
|
||||
|
||||
# Visual Studio files
|
||||
.vs/
|
||||
+1
-1
@@ -138,7 +138,7 @@ See the main documentation for more detailed instructions.
|
||||
|
||||
The unit tests in mpmath/tests/ can be run via the script
|
||||
runtests.py, but it is recommended to run them with py.test
|
||||
(http://codespeak.net/py/dist/index.html), especially
|
||||
(https://pytest.org/), especially
|
||||
to generate more useful reports in case there are failures.
|
||||
|
||||
You may also want to check out the demo scripts in the demo
|
||||
|
||||
@@ -36,6 +36,7 @@ or
|
||||
|
||||
If you have an old version of mpmath installed already, you may have to pass ``easy_install`` the ``-U`` flag to force an upgrade.
|
||||
|
||||
If installation fails, try deleting the following folders: .eggs, mpmath.egg-info, dist, build
|
||||
|
||||
Debian/Ubuntu
|
||||
.............
|
||||
|
||||
@@ -211,7 +211,7 @@ class QuadratureRule(object):
|
||||
the standard interval and then calls :func:`~mpmath.sum_next`.
|
||||
"""
|
||||
ctx = self.ctx
|
||||
I = err = ctx.zero
|
||||
I = total_err = ctx.zero
|
||||
for i in xrange(len(points)-1):
|
||||
a, b = points[i], points[i+1]
|
||||
if a == b:
|
||||
@@ -224,23 +224,26 @@ class QuadratureRule(object):
|
||||
f = lambda x: _f(-x) + _f(x)
|
||||
a, b = (ctx.zero, ctx.inf)
|
||||
results = []
|
||||
err = ctx.zero
|
||||
for degree in xrange(1, max_degree+1):
|
||||
nodes = self.get_nodes(a, b, degree, prec, verbose)
|
||||
if verbose:
|
||||
print("Integrating from %s to %s (degree %s of %s)" % \
|
||||
(ctx.nstr(a), ctx.nstr(b), degree, max_degree))
|
||||
results.append(self.sum_next(f, nodes, degree, prec, results, verbose))
|
||||
result = self.sum_next(f, nodes, degree, prec, results, verbose)
|
||||
results.append(result)
|
||||
if degree > 1:
|
||||
err = self.estimate_error(results, prec, epsilon)
|
||||
if verbose:
|
||||
print("Estimated error:", ctx.nstr(err), " epsilon:", ctx.nstr(epsilon), " result: ", ctx.nstr(result))
|
||||
if err <= epsilon:
|
||||
break
|
||||
if verbose:
|
||||
print("Estimated error:", ctx.nstr(err))
|
||||
I += results[-1]
|
||||
if err > epsilon:
|
||||
total_err += err
|
||||
if total_err > epsilon:
|
||||
if verbose:
|
||||
print("Failed to reach full accuracy. Estimated error:", ctx.nstr(err))
|
||||
return I, err
|
||||
print("Failed to reach full accuracy. Estimated error:", ctx.nstr(total_err))
|
||||
return I, total_err
|
||||
|
||||
def sum_next(self, f, nodes, degree, prec, previous, verbose=False):
|
||||
r"""
|
||||
|
||||
@@ -19,6 +19,10 @@ def test_basic_integrals():
|
||||
assert ae(quadts(lambda x: 2*sqrt(1-x*x), [-1, 1]), pi)
|
||||
mp.dps = 15
|
||||
|
||||
def test_multiple_intervals():
|
||||
y,err = quad(lambda x: sign(x), [-0.5, 0.9, 1], maxdegree=2, error=True)
|
||||
assert abs(y-0.5) < 2*err
|
||||
|
||||
def test_quad_symmetry():
|
||||
assert quadts(sin, [-1, 1]) == 0
|
||||
assert quadgl(sin, [-1, 1]) == 0
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
[pytest]
|
||||
markers =
|
||||
slow: marks tests as slow (deselect with '-m "not slow"')
|
||||
Reference in New Issue
Block a user