2012-09-29 137 views
1

這是在Python代碼,其計算f (x) =∑ ((-1)*x)/(x*x+n*n)
n在1到無限.... 正確至0.0001,對於範圍1 < X < 100在0.1的步驟。
但我得到一個語法錯誤,因爲我是新來的Python編程...爲什麼收到的錯誤語法錯誤:無效語法此代碼

from scipy import * 
    from matplotlib.pyplot import * 
    x=arange(0.1,100,0.1) 
    f=zeros(len(x)) 
    s=-1 
    for n in range (1,10000): 
     t=s*x/(x*x+n*n) 
     f +=t 
     s =-s 
     if max(abs(t))< 1e-4 
      break 
    for xx in c_[x,f]: 
     print "%f %f" % (xx[0],xx[1]) 
+3

有什麼確切的語法錯誤添加:? – halex

+3

冒號?如果max(abs(t))<1e-4: – kalgasnik

+0

你會得到哪種語法錯誤? – mariosangiorgio

回答

7

需要後if max(abs(t))< 1e-4