我正在尝试绘制方波的傅立叶序列,但是对于许多术语,该程序只需要太多时间来计算所有点。我尝试使用多处理模块但没有工作。请帮助我如何使用多处理。我在 fedora linux 上运行并且有一个 AMD FX Octa 内核。谢谢
#!/usr/bin/env python
import pylab,math
#Square Wave approximation by Fourier Series:
#y=4/pi*(sin(x) + sin(3x)/3 + sin(5x)/5 + ... n) terms
n=input("how many terms do you want?")
y=[]
# generate x's to calculate the points.
x=pylab.arange(0,360,0.5)
#generate de odd numbers to add the sines terms
impar=range(1,n+2,2)
no=4/math.pi #just for normalize the sequence to converge to 1 (not pi/4)
#calculate the points
for ps in x:
a=0
for i in impar:
a=a+(((math.sin(math.radians(i*ps)))/i))
a=no*a
y.append(a)
#plot
pylab.figure()
pylab.plot(x,y,"o")
pylab.title(str(n)+str(" terms"))
pylab.grid()
#save a image(just in case)
pylab.savefig(str(n)+str("sqwv.png"))
#show the graph
pylab.show()