0

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.

Ohm
  • 2,312
  • 4
  • 36
  • 75
  • 3
    If you're asking about these concrete curves, the easiest way is just to solve quadratic equation on paper and then code points of intersections. P.S. obviously, the line and parabola can have only 2 intersections points, not 3. – The Godfather Dec 29 '15 at 10:46
  • Other easier option is to use [sympy](http://www.sympy.org/en/index.html) and calculate the matematical solution using symbolyc maths. – Imanol Luengo Dec 29 '15 at 16:07

1 Answers1

1

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.

The Godfather
  • 4,235
  • 4
  • 39
  • 61