Symbolic Integration in Python using Sympy
math, python, symbols, sympy
Solution
`sympy` doesn't always recognize every form, and so sometimes you have to give it a little help:
>>> import sympy
>>> alpha1, r1_x, r1_y = sympy.var("alpha1 r1_x r1_y")
>>> B1 = sympy.exp(-alpha1 * (r1_x**2 + r1_y**2))
>>> B1.integrate(r1_x)
Integral(exp(-alpha1*(r1_x**2 + r1_y**2)), r1_x)
>>> B1.expand(alpha1)
exp(-alpha1*r1_x**2)*exp(-alpha1*r1_y**2)
>>> B1.expand(alpha1).integrate(r1_x)
sqrt(pi)*exp(-alpha1*r1_y**2)*erf(sqrt(alpha1)*r1_x)/(2*sqrt(alpha1))
Problem
I want to integrate exp(-(x^2 + y^2)) in python using sympy library. I could find the integral of exp(-(x^2)) ``` >>> B1 = sympy.exp(-alpha1 * (r1_x**2)) >>> p = integrate(B1,r1_x) >>> p pi**(1/2)*erf(alpha1**(1/2)*r1_x)/(2*alpha1**(1/2)) ``` But when I want to try integrate exp(-(x^2 + y^2)) ``` >>> B1 = sympy.exp(-alpha1 * (r1_x**2 + r1_y**2)) >>> p = integrate(B1,r1_x) >>> p Integral(exp(-alpha1*(r1_x**2 + r1_y**2)), r1_x) ``` There is no output and python can't take the integral!