1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
import numpy as np
def sinc(x): if x == 0.0: return 1.0 else : w = np.pi * x return np.sin(w) / w
print(sinc(0.0), sinc(3.0))
x = np.array([1, 2, 3])
vsinc = np.vectorize(sinc) print(vsinc(x))
import matplotlib.pyplot as plt x = np.linspace(-5, 5, 101) plt.plot(x, vsinc(x)) plt.show()
|