#8321: numerical integration with arbitrary precision
-------------------------+--------------------------------------------------
   Reporter:  burcin     |       Owner:  burcin    
       Type:  defect     |      Status:  new       
   Priority:  major      |   Milestone:  sage-4.5.3
  Component:  symbolics  |    Keywords:            
     Author:             |    Upstream:  N/A       
   Reviewer:             |      Merged:            
Work_issues:             |  
-------------------------+--------------------------------------------------

Comment(by maldun):

 I think I have the solution for this trac with mpmath:

 {{
 def _evalf_(self, f, x, a, b, parent = None):
         """
         Returns numerical approximation of the integral

         EXAMPLES::

             sage: from sage.symbolic.integration.integral import
 definite_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...

         TESTS:

         Check if #3863 is fixed::

             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]

         #Lets try mpmath instead:

         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])
 }}

 The tests just run fine:
 {{
 sage: sage: sage: from sage.symbolic.integration.integral import
 definite_integral
 sage: sage: h = definite_integral(sin(x)/x^2, x, 1, 2); h
 integrate(sin(x)/x^2, x, 1, 2)
 sage: h.n()
 0.472399177268953
 sage: h.n(77)
 0.4723991772689525199904
 sage: h.n(100)
 0.47239917726895251999041133798
 }}

 greez maldun

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/8321#comment:4>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to