sympy
sympy copied to clipboard
Incorrect result when calculating a definite integral as the limit of a Rieman sum
Hello,
I attempted to use sympy to get the definite integral of exp(x) from 1 to 3, not by using the integrate function directly but by getting the limit of the Rieman sum that the integral is equivalent to, that is
limit(2/n*summation(exp(1+(2*i)/n),(i,1,n)),n,'oo')
however the result is 2*E instead of exp(3)-E as would be expected.
The summation gives a Piecewise:
In [57]: summation(exp(1+(2*i)/n),(i,1,n))
Out[57]:
⎛⎧ 2 ⎞
⎜⎪ ─ ⎟
⎜⎪ n ⎟
⎜⎪ n for ℯ = 1⎟
⎜⎪ ⎟
⎜⎪ 2 2⋅(n + 1) ⎟
⎜⎪ ─ ───────── ⎟
ℯ⋅⎜⎨ n n ⎟
⎜⎪ℯ - ℯ ⎟
⎜⎪─────────────── otherwise ⎟
⎜⎪ 2 ⎟
⎜⎪ ─ ⎟
⎜⎪ n ⎟
⎜⎪ 1 - ℯ ⎟
⎝⎩ ⎠
It looks like limit takes the first case when it should take the second. I guess something in limit somewhere is mishandling Piecewise.