3

I tried to calculate the indefinite integral of 1/(L-x)dx in sympy:

from sympy import *
x, L = symbols('x L')
f = 1/(L-x)
integrate(f, x)

it returned:

-log(-L + x)

while it should be:

-log(L-x)

Is it related to sympy or I missed something, thanks for any explanation.

I have not found an answer for this paricular function.

Alexey S. Larionov
  • 6,555
  • 1
  • 18
  • 37
Hadi Pourbagher
  • 151
  • 1
  • 5

3 Answers3

0

If you differentiate both with respect to x, you'll find the same result. You can check with Wolframalpha.

https://www.wolframalpha.com/calculators/derivative-calculator

As far as I understand you haven't provided constraints on L, so it can be positive or negative which I assume is the origin of your confusion. Regardless both formulae yield what you want.

WArnold
  • 275
  • 2
  • 10
  • The Python result is equal to that of the Wolfram alpha integrator for negative values of L, but the results are not the same for positive values. – Hadi Pourbagher Jun 05 '23 at 20:33
  • That is why, when you compute integrals you provide constraints. Both solutions are valid, it just depends on what you assume. – WArnold Jun 06 '23 at 06:44
0

Can't tell you why that happens right now.

However, this is a simple function to integrate, so we can asks sympy to mimic integration by hands with the option manual=True:

f.integrate(x, manual=True)
# out: -log(L-x)

which is the result you are expecting.

Davide_sd
  • 10,578
  • 3
  • 18
  • 30
0

Indefinite integrals are defined only up to an additive constant. The difference between log(x - L) and log(L - x) is I*pi which is a constant.

Considering that you might only be interested in real-valued expressions you might prefer one or the other form but which one integrate should return in that case is still ambiguous: the two expressions differ in that one gives real values for x > L and the other gives real values for x < L.

Oscar Benjamin
  • 12,649
  • 1
  • 12
  • 14