axkr / symja_android_library

:coffee: Symja - computer algebra language & symbolic math library. A collection of popular algorithms implemented in pure Java.
https://matheclipse.org/
GNU General Public License v3.0
382 stars 85 forks source link

Numeric integration returns wrong result for `N[ integrate(1/x,{x,0,1}) ]` #1064

Open tranleduy2000 opened 1 month ago

tranleduy2000 commented 1 month ago

There is the input, the integral of 1/x from 0 to 1 is a divergent integral:

N[ integrate(1/x,{x,0,1}) ] 

Error result:

𝟣𝟢.𝟥𝟩𝟦𝟩𝟨
image

Expected result:

Indeterminate
axkr commented 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?

tranleduy2000 commented 1 month ago

Each numerical integration method has its own strengths and weaknesses. I think the LegendreGauss method is effective in general cases.

tranleduy2000 commented 1 month ago

@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.

https://commons.apache.org/proper/commons-math/javadocs/api-3.6.1/org/apache/commons/math3/analysis/integration/IterativeLegendreGaussIntegrator.html

tranleduy2000 commented 1 month ago

I have some suggestions for determining numerical integral methods: