我試圖找到兩個圖的所有交點並將它們顯示在最終圖上。我環顧四周,嘗試了很多東西,但我一直無法獲得我期待的東西。Python - 查找2個圖的所有交點
目前,我試圖生成,其中交叉點會被列出清單,但我不斷收到以下錯誤:
The truth value of an array with more than one element is ambiguous. Use
a.any()
ora.all()
.
import numpy as np
from scipy.optimize import fsolve
import matplotlib.pyplot as plt
x = np.arange(-7.0, 7.0, 0.05)
def y(x):
return np.sin(x)*(0.003*x**4 - 0.1*x**3 + x**2 + 4*x + 3)
def g(x):
return -10 * np.arctan(x)
def intersection(x):
if (y(x) - g(x)) == 0:
print y.all(x)
plt.plot(x, y(x), '-')
plt.plot(x, g(x), '-')
plt.show()
哪一行會引發錯誤? – soon