1
我的失误与无限因子和XD我重做代码后,但我不断收到语法错误:\无效的语法绘制
from scitools.std import *
from math import factorial, cos, e
from scipy import *
import numpy as np
def f1(t):
return 0.5*(1 + sum((a**(2*n)*cos(2*sqrt(1 + n)*t))/(e**a**2*factorial(n)) for n in range(0,100)))
a=4
t = linspace(0, 35, 1000)
y1 = f1(t)
plot(t, y1)
xlabel(r'$\tau$')
ylabel(r'P($\tau$)')
legend(r'P($\tau$)')
axis([0.0, 35.0, 0.0, 1.0])
grid(True)
show()
它说,有一个在我的程序中的错误:无效的语法和a是红色的:\
现在有什么问题? :(
编辑:
我在总和年底又增加了),但现在我不断收到巨大的错误:
Traceback (most recent call last):
File "D:\faxstuff\3.godina\kvantna\vježbe\qm2\v8\plot.py", line 12, in <module>
y1 = f1(t)
File "D:\faxstuff\3.godina\kvantna\vježbe\qm2\v8\plot.py", line 8, in f1
return 0.5*(1 + sum((a**(2*n)*cos(2*sqrt(1 + n)*t))/(e**a**2*factorial(n)) for n in range(0,100)))
File "C:\Python26\lib\site-packages\numpy\core\fromnumeric.py", line 1415, in sum
res = _sum_(a)
File "D:\faxstuff\3.godina\kvantna\vježbe\qm2\v8\plot.py", line 8, in <genexpr>
return 0.5*(1 + sum((a**(2*n)*cos(2*sqrt(1 + n)*t))/(e**a**2*factorial(n)) for n in range(0,100)))
TypeError: unsupported operand type(s) for /: 'numpy.ndarray' and 'numpy.float64'
我应该使之表达还给一个数组,我可以绘制或?
您的第二个错误是与您的第一个错误不同的问题。请提出一个新问题。 – 2011-05-23 18:53:57