且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Python-查找2个图的所有交点

更新时间:2023-02-26 20:34:49

它类似于:

在Python中两个图的交点,找到x值:

import numpy as np
from scipy.optimize import fsolve
import matplotlib.pyplot as plt


x = np.arange(-7.0, 7.0, 0.05)

y = np.sin(x)*(0.003*x**4 - 0.1*x**3 + x**2 + 4*x + 3)

g = -10 * np.arctan(x)

def intersection():
    idx = np.argwhere(np.isclose(y, g, atol=10)).reshape(-1)
    print idx

    plt.plot(x, y, '-')
    plt.plot(x, g, '-')

    plt.show()

intersection()

您不使用函数,而是使用值列表

edit: you don't use a function, but a list of values