I have a problem with numerical integration in Sagemath.
The following exemple tries to use a (ridiculously oversimplified) example of a Uniform(-1,1) density, and to integrate it. (And yes, I know that the sought function is , thank you very much...).
What bothers me is not the "interesting" part of the integral ; it's what happens in the "uninteresting" (constant) parts...
The function itsel plots (and therefore probably computes) fine.
However, its numerical integral has some serious problems :
This is probably not an artifact of plot : "zooming" on a problematic region, justs zooms on the same problem (i. e. not dependent of choice of plotting points) :
This might originate in Maxima, which exhibits the same behaviour :
Let's try quad (from mpmath), a nice low-dimension quadrature function, used by sympy :
This becomes ridiculous. Let's zoom in the first problematic region...
This is becoming preposterous. Let's zoom again...
Theorem: Numerical analysis in hard.
Corollary: Numerical analysis is harder in apparently simple cases...
Proofs: Plotting a constant function is not (not hard). an erroneous plot is not a not-hard plot. See above...
More seriously : What can be the source of the problem ? I am aware that I am using very general algorithms in a special case susceptible of many simplifications (starting with using the closed form of the integral...). But this is a test case, prelude to more complex cases with no obvious simplifications.
Any ideas ?
Well, let's try to force dunif to accept and return floating point values : that should take care of "surprising" conversions :
Same difference, again... The problem is not here.
Let's try R's integration routine :
** Same problem ?!?!?! **
So far, we tried three implementations (Sage-Maxima, mpmath, R) of numerical integration routines on the same trivial example, which gave variations of the same error.
Either these routines implement variations of the same flawed algorithm, my proble is ill-thought or these routines use the same flawed piece of system software in some critical part of their algorithms...