# 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

b


176  176  pass 
177  177  return None 
178  178  
179   def _evalf_(self, f, x, a, b, parent=None): 
 179  def _evalf_(self, f, x, a, b, parent = None): 
180  180  """ 
181  181  Returns numerical approximation of the integral 
182  182  
… 
… 

186  186  sage: h = definite_integral(sin(x)*log(x)/x^2, x, 1, 2); h 
187  187  integrate(log(x)*sin(x)/x^2, x, 1, 2) 
188  188  sage: h.n() # indirect doctest 
189   0.14839875208053... 
 189  0.472399177268953 
190  190  
191  191  TESTS: 
192  192  
… 
… 

194  194  
195  195  sage: integrate(x^2.7 * e^(2.4*x), x, 0, 3).n() 
196  196  0.154572952320790 
 197  
 198  #Check if #8321 is fixed: 
 199  
 200  sage: d = definite_integral(sin(x)/x^2, x, 1, 2) 
 201  sage: d.n(77) 
 202  0.4723991772689525199904 
197  203  """ 
198   from sage.gsl.integration import numerical_integral 
199   # The gsl routine returns a tuple, which also contains the error. 
200   # We only return the result. 
201   return numerical_integral(f, a, b)[0] 
 204  
 205  import sage.libs.mpmath.all as mpmath 
 206  
 207  try: 
 208  precision = parent.prec() 
 209  mpmath.mp.prec = precision 
 210  except AttributeError: 
 211  precision = mpmath.mp.prec 
 212  
 213  mp_f = lambda z: \ 
 214  f(x = mpmath.mpmath_to_sage(z,precision)) 
 215  
 216  return mpmath.call(mpmath.quad,mp_f,[a,b]) 
202  217  
203  218  def _tderivative_(self, f, x, a, b, diff_param=None): 
204  219  """ 