1 回答

TA贡献1820条经验 获得超9个赞
我不认为 numpy 和 sympy 一起玩得很好,除非你lambdify的 sympy 方程。而且我也不确定NaN值,这似乎在您的等式中。
你可以用数字试试。在绘制函数时,我发现该范围内没有最小值,但导数中有最大值:
import numpy as np
from matplotlib import pyplot as plt
from scipy.signal import argrelmax
x = np.linspace(-10, -6, 256) # generate x range of interest
y = np.sqrt((x+6)**2 + 25) + np.sqrt((x-6)**2 - 121)
dydx = (x - 6)/np.sqrt((x - 6)**2 - 121) + (x + 6)/np.sqrt((x + 6)**2 + 25)
maximum, = argrelmax(dydx) # returns index of maximum
x[maximum]
>>> -8.50980392
# plot it
plt.plot(x, y)
ax = plt.gca().twinx() # make twin axes so can see both y and dydx
ax.plot(x, dydx, 'tab:orange')
ax.plot(x[maximum], dydx[maximum], 'r.')
添加回答
举报