1

方形波のフーリエ列をプロットしようとしていますが、多くの項があるため、プログラムはすべての点を計算するのに時間がかかりすぎます。multiprocessing モジュールを使用しようとしましたが、うまくいきませんでした。multiprocessing の使用方法を教えてください。私は 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()
4

2 に答える 2