AlwaysStuck
AlwaysStuck

Reputation: 51

Trouble using Sympy to integrate

So I've been using Sympy as a tool for integration in python. Usually I have no problem but this time it isn't giving me a very useful answer.

from sympy import *
psi, x, a = symbols('psi, x, a') #Where a is a real constant 
def psi(x):
    return 1./(x**2 + a**2)
I = integrate(psi(x)**2 ,(x,-oo,oo))  #No complex conjugate 
print I 

a is supposed to be a real constant and the solution should equal one, its a wave function and I need to find a. Anyone who could help me to find a better way on to how to integrate this would be appreciated.

The answer for this integration should be: 0.5*pi* (1./a**2)**1.5

Upvotes: 1

Views: 437

Answers (1)

Aung
Aung

Reputation: 463

You can use assumption(positive=True) depending on your variable to simplify. Here is the example.

from sympy import *
psi, x, a = symbols('psi, x, a',positive=True) #Where a is a real constant 
def psi(x):
    return 1./(x**2 + a**2)
I = integrate(psi(x)**2 ,(x,-oo,oo))  #No complex conjugate 
print I 

The answer would be 0.5*pi/a**3 which is the right answer.

Upvotes: 1

Related Questions