sympy icon indicating copy to clipboard operation
sympy copied to clipboard

Incorrect result when calculating a definite integral as the limit of a Rieman sum

Open mivuzu opened this issue 7 months ago • 1 comments

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.

mivuzu avatar May 04 '25 21:05 mivuzu

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.

oscarbenjamin avatar May 04 '25 22:05 oscarbenjamin