Ohm
Ohm

Reputation: 2442

Finding three intersections of two curves using Python

I am trying to locate the three intersections of two curves. One is v1(u) = u - u^3 and the other is v2(u) = (u-a0)/a1 (where a0 and a1 are some parameters). So far I have managed to figure out how to plot the intersections:

import matplotlib.pyplot as plt
import numpy as np
u = np.linspace(-2,2,1000)
a0 = 0
a1 = 2
v1 = u - u**2
v2 = (u - a0)/a1
plt.plot(u,v1, 'g-')
plt.plot(u,v2, 'b-')
idx = np.argwhere(np.isclose(v1, v2, atol=0.1)).reshape(-1)
plt.plot(u[idx], v1[idx], 'ro')
plt.show()

The question is how can I get the u value of the three intersection points.

Upvotes: 0

Views: 482

Answers (1)

okainov
okainov

Reputation: 4654

Solve quadratic equation ang get these two (or one or zero, depend on coefficients; but not three, obviously) intersection points:

enter image description here

But if you're looking for a way to compute intersections for absolutely custom functions, the only was is numeric methods, please refer to Root-finding algorithms

To solve cubic equation analytically you can try Cardano's method or some other method described on Wiki.

Upvotes: 1

Related Questions