# encoding: gbk
# 傅里叶级数
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(0, 6*np.pi, 0.01)
n = 1 # 频率倍数n, 取1,3,5,7,9等
y = 1/n * np.sin(n * x)
plt.plot(x, y * 4 / np.pi)
plt.title("n="+str(n))
plt.show()
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(0, 6*np.pi, 0.01)
y = np.sin(x)
label = "1"
for n in range(2, 4):
if n % 2 != 0:
label = label+","+str(n)
print(n)
y = y + 1/n * np.sin(n * x)
plt.plot(x, y * 4 / np.pi)
plt.title("n="+label)
plt.ylim(-1.5, 1.5)
plt.show()
页面更新:2024-02-24
本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828
© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号