Open tranleduy2000 opened 1 month ago
Integrate
function switches to NIntegrate
function in numeric mode:
For the NIntegrate
function the LegendreGauss
method is the default numeric method for the calculation.
See these JUnit tests:
Maybe we should use another default method for NIntegrate
?
Any suggestions?
Each numerical integration method has its own strengths and weaknesses. I think the LegendreGauss
method is effective in general cases.
@axkr I suggest to use the Romberg
as the default method, since LegendreGauss
fails in many common cases:
This algorithm divides the integration interval into equally-sized sub-interval and on each of them performs a Legendre-Gauss quadrature. Because of its non-adaptive nature, this algorithm can converge to a wrong value for the integral (for example, if the function is significantly different from zero toward the ends of the integration interval). In particular, a change of variables aimed at estimating integrals over infinite intervals as proposed here should be avoided when using this class.
I have some suggestions for determining numerical integral methods:
If the expression has Abs
function, use the LegendreGauss
method
Example input: Integrate[Abs(x^2-2x), {x, -10, 10}] // N
Result should be 669.3282335875249
If the expression contains a variable that occurs in the exponent of Power
function, use the GaussKronrod
method
Example input: x^x
, 3^(2x)
, E^(-Sin(t))
Otherwise, use the Romberg
method, since it is the optimized version of trapezoid and Simpson methods
There is the input, the integral of
1/x
from 0 to 1 is a divergent integral:Error result:
Expected result: