代碼,請參閱代碼片斷片斷1:sympy中的積分對於x * cos(n * pi * x/L)不起作用,但對sqrt(1。)* x * cos(n * pi * x/L)有效。下面
from sympy import symbols, integrate, cos, pi
from numpy import sqrt
n = symbols('n', integer=True)
x, L = symbols('x L', real=True)
fs_coeff = integrate(sqrt(1.)*x*cos(n*pi*x/L), (x, 0, L))
print fs_coeff
我也得到:
-1.0 *分段((0,N == 0),(0.101321183642338 * L * 2/N * 2,True))+ 1.0 *分段((L ** 2/2,n == 0),(0.318309886183791 * L ** 2 * sin(3.14159265358979 * n)/ n + 0.101321183642338 * L ** 2 * cos (3.14159265358979 * N)/ N ** 2,TRUE))
代碼段2:
from sympy import symbols, integrate, cos, pi
from numpy import sqrt
n = symbols('n', integer=True)
x, L = symbols('x L', real=True)
fs_coeff = integrate(x*cos(n*pi*x/L), (x, 0, L))
print fs_coeff
我得到一個錯誤:
回溯(最近通話最後一個):
文件 「test-sympy.py」,第6行,在
fs_coeff =整合(X * COS( N * PI * X/L),(X,0,1))
...
ValueError異常:值過多解壓
我使用的拉泰什t Enthought Canopy python發行版,1.3版。 Python版本2.7.6,SymPy 0.7.3。
如果您對此有任何意見,我將不勝感激。
是的,這工作!謝謝! – user3304293