# Ticket #8321: trac_8321_numeric_int_mpmath.patch

File trac_8321_numeric_int_mpmath.patch, 1.9 KB (added by maldun, 12 years ago)

Numerical evaluation of symbolic integration with arbitrary precision with help of mpmath

• ## sage/symbolic/integration/integral.py

```# HG changeset patch
# User maldun <domors@gmx.net>
# Date 1282750756 -7200
# Node ID 8ec2c3b4276b0805902889a972a1502e545913a5
# Parent  5b338f2e484f2065d3d30d47bc204d6e9ed13d12
Trac 8321: Numerical evaluation of symbolic integrals with arbitrary precision is now possible, with help of mpmath

diff -r 5b338f2e484f -r 8ec2c3b4276b sage/symbolic/integration/integral.py```
 a pass return None def _evalf_(self, f, x, a, b, parent=None): def _evalf_(self, f, x, a, b, parent = None): """ Returns numerical approximation of the integral sage: h = definite_integral(sin(x)/x^2, x, 1, 2); h integrate(sin(x)/x^2, x, 1, 2) sage: h.n() # indirect doctest 0.4723991772689525... 0.472399177268953 TESTS: sage: integrate(x^2.7 * e^(-2.4*x), x, 0, 3).n() 0.154572952320790 #Check if #8321 is fixed: sage: d = definite_integral(sin(x)/x^2, x, 1, 2) sage: d.n(77) 0.4723991772689525199904 """ from sage.gsl.integration import numerical_integral # The gsl routine returns a tuple, which also contains the error. # We only return the result. return numerical_integral(f, a, b)[0] import sage.libs.mpmath.all as mpmath try: precision = parent.prec() mpmath.mp.prec = precision except AttributeError: precision = mpmath.mp.prec mp_f = lambda z: \ f(x = mpmath.mpmath_to_sage(z,precision)) return mpmath.call(mpmath.quad,mp_f,[a,b]) def _tderivative_(self, f, x, a, b, diff_param=None): """