使用 sympy,我得到了一个函数的导数:
>>> import sympy as sp
>>> x = sp.Symbol('x')
>>> f = -0.01 * sp.sin(0.05 * x - 0.7) + 0.01 * sp.sin(6.2 * x + 4.5)
>>> f.diff(x)
−0.0005cos(0.05𝑥−0.7)+0.062cos(6.2𝑥+4.5)
我构建了一个函数及其导数的图表:
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(100)
plt.plot(x, -0.01 * np.sin(0.05 * x - 0.7) + 0.01 * np.sin(6.2 * x + 4.5), 'b-')
plt.twinx()
plt.plot(x, -0.0005 * np.cos(0.05 * x - 0.7) + 0.062 * np.cos(6.2 * x + 4.5), 'g-')
plt.plot(plt.xlim(), [0, 0], 'k--')
plt.show()
导数为零的地方似乎不是极值。我不明白为什么。