On Thu, 23 Sep 2010 02:34:09 -0400 Jonathan Bober <jwbo...@gmail.com> wrote:
> In sage it seems there are a few different ways to get a numeric > approximation to an integral. There are the top level functions > integral and numerical_integral (and their synonyms), and then > symbolic expressions have a method nintegrate. So if f is a symbolic > expression, > > 1.) numerical_integral(f, 0, 1) > 2.) integral(f, x, 0, 1).n() and > 3.) f.nintegrate(x, 0, 1) > > do 3 different things. Maybe there are also other "top level" ways of > definite integration that don't require either an import statement or > a direct call to mpmath. > > I think I would like 1 and 3 to do the exact same thing. I don't know > if there is a good reason for them to be different. (I do know that I > might often be interested in integrating things that aren't symbolic > expressions, though.) I think that the behavior of integral().n() that > you list above is reasonable, though. If it fails like in the first > example you have above, then that is probably a _different_ bug. And > the second example is a type of problem we will probably always have > to deal with. (I have a similar example that came up in the "real > world" that I might try to dig up because I think it will have the > same bad behavior.) AFAIK, the reason 1 and 3 work differently is mostly historic. Fixing this could be a part of #7763: http://trac.sagemath.org/sage_trac/ticket/7763 The behavior of integral().n() has to be different from numerical_integral() since integral() first tries to integrate symbolically. One can use integral(..., hold=True).n() to get a similar effect, but the options you can pass to the numerical evaluation routines of symbolic expressions are limited at the moment. > A different behavior that I would find reasonable is for > integral().n() to _never_ do numeric integration. If integral() can't > get an exact answer, then integral().n() could just give an error and > ask the user to call numerical_integral() if that's what's wanted. I would be OK with this as well. > If integral().n() always did numeric integration, then it would of > course suffer from the problems below. How does doing N[Integrate[ ... ]] in MMA compare to using NIntegrate? Cheers, Burcin -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org