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!
SymPy also has a Symbols() function that can define multiple symbols at once. String contains names of variables separated by comma or space. In SymPy's abc module, all Latin and Greek alphabets are defined as symbols. Hence, instead of instantiating Symbol object, this method is convenient.
Symbolic math variables are declared using SymPy's symbols() function. Note, the arguments passed to the symbols() function (symbol names) are separated by a space, no comma, and surrounded by quotes. The output of the symbols() function are SymPy symbols objects.
SymPy stands for Symbolic Mathematics in Python and is a Python library for dealing with mathematics. It is one of the core libraries of the SciPy Ecosystem among other giants like NumPy, Pandas, and Matplotlib. With SymPy you can manipulate mathematical expressions.
(I am the lead developer of SymPy)
DSM is correct that you can get this to work by calling expand, and that there is no general way to do this (because in general, integrals don't have closed forms).
I just wanted to point out that if SymPy cannot do an integral that does have a closed form, we consider this a bug, and you should feel free to report it at http://code.google.com/p/sympy/issues.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With