【发布时间】:2015-07-04 21:42:05
【问题描述】:
sympy 给了我以下表达式:
2.8*x**2 - 4.0*x*Integral(1.0*x**2*sqrt(-x**2 + 1), (x, -1.0, 0.0)) + 1.33333333333333*x + 0.133333333333333
我希望 sympy 给我系数的数值。我怎样才能做到这一点? .evalf 和 N() 不起作用。
这是我的代码
from numpy import *
from sympy import *
from matplotlib.pyplot import *
x = Symbol ('x')
#The function we are required to approximate
f1 = -1.0*x
f2 = 1.0*x
phi_0=1.0
phi_1 = 2.0*x
phi_2 = 4.0*x*x-1
w = 1.0*sqrt(1.0-x*x)
#compute the coefficient
c_0 = integrate(f1*phi_0*w, (x, -1.0, 0.0))+integrate(f2*phi_0, (x, 0.0, 1.0))
c_1 = integrate(f1*phi_1*w, (x, -1.0, 0.0))+integrate(f2*phi_1, (x, 0.0, 1.0))
c_2 = integrate(f1*phi_2*w, (x, -1.0, 0.0))+integrate(f2*phi_2, (x, 0.0, 1.0))
fapprox2 = c_0*phi_0+c_1*phi_1+c_2 *phi_2
【问题讨论】:
标签: python python-2.7 numpy scipy sympy