How to find the intersection of two curves?

Multi tool use
Multi tool use


How to find the intersection of two curves?



How do I find the intersection of two curves given by arrays y1 and y2, having the same x values? This is my current code:


y1


y2


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

fig = plt.figure()
ax = fig.add_subplot(111)
Ls = [2, 4]
for L in range(len(Ls)):
x = np.arange(10)
y1 = np.array([2, 4, 6, 8, 10, 12, 14, 16, 18, 20])
y2 = np.array([20, 18, 16, 14, 12, 10, 8, 6, 4, 2])
ax.plot(x, y1, x, y2)
ax.set_label("x")
ax.set_label("y")

f = np.sign(y1 - y2)
optimize.bisect(f, 4, 6)



I'm getting an error in bisect:


bisect


...
File "...scipyoptimizezeros.py", line 249, in bisect
r = _zeros._bisect(f,a,b,xtol,rtol,maxiter,args,full_output,disp)
TypeError: 'numpy.ndarray' object is not callable





Have you tried using numpy's intersect1d() method?
– Rahul Bohare
Jul 3 at 10:03


intersect1d()





What is the expected output in your example? When talking about the intersection of datasets, it usually means common elements. What you want to know is the intersection of curves, which is related but not the same thing. Please also include all imports to make the example runnable.
– Dev-iL
Jul 3 at 16:05





See stackoverflow.com/questions/50437865/…
– Warren Weckesser
Jul 3 at 17:52





Possible duplicate of finding the interpolated intersection between two arrays in Python/Numpy/Scipy
– Dev-iL
Jul 4 at 8:18









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Uhgyqdiv7
0sMG9yhi,hlwrAaKU,wJhr NBCmb6dnD3sk0v,8ffNTB9C2 1V

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications