请问用sympy后得到的是个表达式,怎么样把他计算出来呢
from sympy import *>>> x = symbols("x")
>>> def outter(u,q):# 定义一个正态分布
def inner(x):
return exp( (x - u)**2 / ((-2) * q**2) )/ (sqrt(2*math.pi) * q)
return inner
>>> f = outter(1,1)
>>> integrate(f(x),(x,float(0),float(2)))
0.398942280401433*sqrt(2)*sqrt(pi)*erf(0.5*sqrt(2)) # 这个表达式怎么样才能把他计算出具体的浮点数呢? from math import *
eval(integrate(f(x),(x,float(0),float(2))).__repr__()) from sympy import *
import math
def outter(u,q):
def inner(x):
return exp( (x - u)**2 / ((-2) * q**2) )/ (sqrt(2*math.pi) * q)
return inner
x = symbols("x")
f = outter(1,1)
d = integrate(f(x),(x,float(0),float(2)))
print(d . evalf())
运行实况:
D:\\Python>python x.py
0.682689492137086
D:\\Python>
页:
[1]