Indefinite integral of 1/(L-x) dx in sympy python

74 Views Asked by At

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.

3

There are 3 best solutions below

2
On

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.

0
On

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.

0
On

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.