I am trying to find the zero's of several straight lines solving one of them at a time with fsolve function. I can't manage to write a decent code that will do this, this below is my best attempt so far, any help is very much appreciated. I think the best way to do it is to define a class (the class being the line with its two properties i.e the slope and the y intercept) but I do not know how to do this.
import numpy as np
from scipy.optimize import fsolve
def straight_line(parameters):
m = parameters[0] # This is the first parameter of the line i.e the slope
n = parameters[1] # This is the second parameter of the line i.e. the y-axis intercept
x = parameters[3] # This is the variable of the function, I want to find x such that m * x + n = 0
return m * x + n
for m in range(-10,10):
for n in range(-10,10):
guess = 1
zero = fsolve(straight_line([m, n]), guess) # This is not correct
print([m, n, zero])