1

The problem is to find the value from the red line intersecting the 0.0 level (black line). The red line is plotted as follows:

plt.plot(C, iG, color='r')
plt.plot(C, iG, 'o', color='r', markersize=6)

and the black line is plotted with:

plt.axhline(y=0, color='k')

Variables are here:

C = [0, 20, 40, 60, 80, 100]
iG = [1.3872346819371657, 0.7872943505903507, 0.17782668886707143, -0.44058186267346144, -1.0673973968907333, -1.7021324469635957]

So, there is only one line (i.e., 6 x,y pairs that form the red line).

Figure is here:

figure

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Gery
  • 8,390
  • 3
  • 22
  • 39

1 Answers1

2

You can simply solve it mathematically. If you take a line y = mx + c, the x intercept is where y = 0, so solve 0 = mx + c:

0 = mx + c  
-c = mx  
-c/m = x  

therefore in line y = mx + c x_intercept = -c/m = x

In order to convert your variables into the y = mx + c form, you use point-slope form: y - y1 = m(x - x1) where y1 and x1 are the coordinates of a point on your line (x1, y1). Find the slope using two of your coordinates, and then complete the equation. As before, y = 0:

0 - y1 = m(x - x1)
-y1 = mx - mx1
-y1/m = x - x1
-y1/m + x1 = x

Code of how this could be done below:

# points inputted as a list of the x and y values of the points
def find_xintercept(point1, point2):

    # slope (m) = rise over run
    slope = (point1[1] - point2[1]) / (point1[0] - point2[0])
    return -point1[1] / slope + point1[0]

example:

print(find_xintercept([C[0], iG[0]], [C[1], iG[1]]))

prints:

46.24575510110953
Maxijazz
  • 175
  • 1
  • 11
  • 1
    wonderful answer, thank you very much. I was wondering about the slope and getting that value mathematically before posting here, I found this link `https://nessy.info/?p=16` but could not implement it, I am newbie in Python, I now understand how this works with your example. Thanks a trillion! – Gery Oct 11 '20 at 22:17