Solving Integral with Symbolic Computation (Sympy), Division and Tricky Limits

300 Views Asked by At

A physics teacher on an online course presented this integral,

$$ = \frac{1}{4\pi\epsilon_0} \frac{Q x}{L} \int _{-L/2}^{L/2} \left(\frac{dy}{(x^2+y^2)^{3/2}} \right) \hat{x} $$

and said she solved it with Wolfram Alpha, which gave

$$ = \frac{1}{4\pi\epsilon_0} \frac{Q}{x \sqrt{x^2 + (L/2)^2}}\hat{x} $$

I was wondering how to solve this using any other symbolic software like Sympy. I tried this for the indefinite integral,

from sympy import integrate, sqrt, Symbol, pprint
y = Symbol('y')
x = Symbol('x')
print (integrate('1/ ((x**2+y**2)**(3/2))',y))

Result is

y/(x**3*sqrt(1 + y**2/x**2))

I plugged in the limits,

from sympy import simplify
L = Symbol('L')
x = Symbol('x')
simplify((L/2)/(x**3*sqrt(1 + (L/2)**2/x**2)) - \
         (-L/2)/(x**3*sqrt(1 + (-L/2)**2/x**2)))

I get

2*L/(x**3*sqrt(L**2/x**2 + 4))

which does not look right. Does anyone have any experience solving integrals such as the one above using symbolic software?