这是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])
Run Code Online (Sandbox Code Playgroud)