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.')
添加回答
舉報