[英]Trouble using Sympy to integrate
So I've been using Sympy as a tool for integration in python. 因此,我一直在使用Sympy作为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. a应该是一个实常数,解应该等于1,它是波动函数,我需要找到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 这种集成的答案应该是:0.5 * pi *(1./a**2)**1.5
You can use assumption( positive=True
) depending on your variable to simplify. 您可以根据变量使用假设(
positive=True
)来简化。 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. 答案将是
0.5*pi/a**3
,这是正确的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.