矩形波
周期为 2 π 2\pi 2π的矩形波函数:
z ( t ) = { − 1 , − π ≤ t < 0 1 , 0 ≤ t < π z(t)=\begin{cases}-1,-\pi\le t\lt 0\\\quad 1,\quad0\le t\lt \pi\end{cases} z(t)={−1,−π≤t<01,0≤t<π
= 4 π [ sin t + 1 3 sin 3 t + ⋯ + 1 2 n + 1 sin ( 2 n + 1 ) t + ⋯ ] =\frac{4}{\pi}\left[\sin t+\frac{1}{3} \sin 3 t+\cdots+\frac{1}{2 n+1} \sin (2 n+1) t+\cdots\right] =π4[sint+31sin3t+⋯+2n+11sin(2n+1)t+⋯]
import matplotlib.pyplot as plt
import numpy as np
import random
def randomColor(num):
'''随机颜色'''
colors = []
for i in range(num):
colArr = ['1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']
color = ""
for i in range(6):
color += colArr[random.randint(0, 14)]
if any(color in colExiting for colExiting in colors):
continue
colors.append("#" + color)
return colors
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
w = np.arange(1, 30, 2) # 角频率
z = 0
colors = randomColor(len(w))
x = np.arange(-8, 8, 0.01)
font = {'family': 'serif',
'weight': 'normal',
'size': 14,
}
for c, n in zip(colors, np.arange(0, len(w))):
z_i = np.sin(w[n] * x) / w[n]
z = z + z_i
l = r'$\frac{sin(%dt)}{%d}$' % (2 * n + 1, 2 * n + 1)
ax.scatter(x, w[n], z_i, color=c, alpha=0.5, linewidths=0.01)
ax.text(12 - n % 2 * 2, w[n] - 1, 0, l, fontdict=font)
ax.scatter(x, -1, z, color='r', alpha=0.5, linewidths=0.01)
ax.set_zlim(-1.5, 1.5)
ax.set_xlabel('t')
ax.set_ylabel('w')
ax.set_zlabel('z')
plt.show()
e x \mathrm{e}^{x} ex
e x = 1 + x + x 2 2 ! + ⋯ + x n n ! + ⋯ ) \mathrm{e}^{x}=1+x+\frac{x^{2}}{2 !}+\cdots+\frac{x^{n}}{n !}+\cdots) ex=1+x+2!x2+⋯+n!xn+⋯)
import matplotlib.pyplot as plt
import numpy as np
import random
def randomColor(num):
'''随机颜色'''
colors = []
for i in range(num):
colArr = ['1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']
color = ""
for i in range(6):
color += colArr[random.randint(0, 14)]
if any(color in colExiting for colExiting in colors):
continue
colors.append("#" + color)
return colors
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
w = np.arange(1, 36, 2)
z = 0
colors = randomColor(len(w))
x = np.arange(-6, 6, 0.01)
font = {'family': 'serif',
'weight': 'normal',
'size': 14,
}
for c, n in zip(colors, np.arange(0, len(w))):
z_i = x**n/np.math.factorial(n)
z = z + z_i
l = r'$\frac{x^{%d}}{%d!}$' % (n,n )
ax.scatter(x, w[n], z_i, color=c, alpha=0.5, linewidths=0.01)
ax.text(12 - n % 2 * 2, w[n] - 1, 0, l, fontdict=font)
ax.scatter(x, -1, z, color='r', alpha=0.5, linewidths=0.01)
ax.set_zlim(-6, 6)
ax.set_zticks([])
ax.set_xlabel('t')
ax.set_ylabel('w')
ax.set_zlabel('z')
plt.show()
sin x \sin x sinx
sin x = x − x 3 3 ! + ⋯ + ( − 1 ) n ( 2 n + 1 ) ! x 2 n + 1 + ⋯ \sin x=x-\frac{x^{3}}{3 !}+\cdots+\frac{(-1)^{n}}{(2 n+1) !} x^{2 n+1}+\cdots sinx=x−3!x3+⋯+(2n+1)!(−1)nx2n+1+⋯
import matplotlib.pyplot as plt
import numpy as np
import random
def randomColor(num):
'''随机颜色'''
colors = []
for i in range(num):
colArr = ['1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']
color = ""
for i in range(6):
color += colArr[random.randint(0, 14)]
if any(color in colExiting for colExiting in colors):
continue
colors.append("#" + color)
return colors
def getSign(x):
if x>=0:
return ''
else:
return '-'
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
w = np.arange(1, 30, 2)
z = 0
colors = randomColor(len(w))
x = np.arange(-8, 8, 0.01)
font = {'family': 'serif',
'weight': 'normal',
'size': 14,
}
for c, n in zip(colors, np.arange(0, len(w))):
z_i = (-1)**n*x**(2*n+1)/np.math.factorial(2*n+1)
z = z + z_i
l=r'$\frac{%sx^{%d}}{%d!}$'% (getSign((-1)**n),2*n+1,2*n+1)
ax.scatter(x, w[n], z_i, color=c, alpha=0.5, linewidths=0.01)
ax.text(12 - n % 2 * 3, w[n] - 1, 0, l, fontdict=font)
ax.scatter(x, -1, z, color='r', alpha=0.5, linewidths=0.01)
ax.set_zlim(-6, 6)
ax.set_zticks([])
ax.set_xlabel('t')
ax.set_ylabel('w')
ax.set_zlabel('z')
plt.show()
cos x \cos x cosx
cos x = 1 − x 2 2 ! + ⋯ + ( − 1 ) n ( 2 n ) ! x 2 n + ⋯ \cos x=1-\frac{x^{2}}{2 !}+\cdots+\frac{(-1)^{n}}{(2 n) !} x^{2 n}+\cdots cosx=1−2!x2+⋯+(2n)!(−1)nx2n+⋯
import matplotlib.pyplot as plt
import numpy as np
import random
def randomColor(num):
'''随机颜色'''
colors = []
for i in range(num):
colArr = ['1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']
color = ""
for i in range(6):
color += colArr[random.randint(0, 14)]
if any(color in colExiting for colExiting in colors):
continue
colors.append("#" + color)
return colors
def getSign(x):
if x>=0:
return ''
else:
return '-'
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
w = np.arange(1, 30, 2)
z = 0
colors = randomColor(len(w))
x = np.arange(-8, 8, 0.01)
font = {'family': 'serif',
'weight': 'normal',
'size': 14,
}
for c, n in zip(colors, np.arange(0, len(w))):
z_i = (-1)**n*x**(2*n)/np.math.factorial(2*n)
z = z + z_i
l=r'$\frac{%sx^{%d}}{%d!}$'% (getSign((-1)**n),2*n,2*n)
ax.scatter(x, w[n], z_i, color=c, alpha=0.5, linewidths=0.01)
ax.text(12 - n % 2 * 3, w[n] - 1, 0, l, fontdict=font)
ax.scatter(x, -1, z, color='r', alpha=0.5, linewidths=0.01)
ax.set_zlim(-6, 6)
ax.set_zticks([])
ax.set_xlabel('t')
ax.set_ylabel('w')
ax.set_zlabel('z')
plt.show()