我试图找到两个图形的所有交点,并在最终的绘图中显示它们。我环顾四周,尝试了很多东西,但我没能得到我想要的东西。
目前,我正在尝试生成一个列表,其中列出了交叉点,尽管我一直得到以下错误:
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()
对于单个解决方案,这在http://glowingpython.blogspot.de/2011/05/hot-to-find-intersection-of-two.html中得到了回答:
现在,您只需要遍历您的范围来获得所有根。这将提供一些重复项,可以通过使用mpmath、将精度设置得足够低以及使用集合来删除这些重复项。
类似于:
Intersection of two graphs in Python, find the x value:
编辑:您不使用函数,而是使用值列表
相关问题 更多 >
编程相关推荐