# Ticket #8321: trac_8321_rebase.patch

File trac_8321_rebase.patch, 1.9 KB (added by benjaminfjones, 11 years ago)

rebase of previous patch to 4.7.1

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

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

diff --git a/sage/symbolic/integration/integral.py b/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)*log(x)/x^2, x, 1, 2); h integrate(log(x)*sin(x)/x^2, x, 1, 2) sage: h.n() # indirect doctest 0.14839875208053... 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): """