Solving Equations With Parameters Python Fsolve
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
Solution 1:
zero = fsolve(straight_line([m, n]), guess)
The problem is that you call straight_line() and send the calculated value to fsolve. If you read the documentation, you will see that the first parameter to fsolve, must be a "callable". In other words, you need to pass the function itself:
zero = fsolve(straight_line, guess)
You also need to pass the args to define the line, in this case the slope and y-intercept:
zero = fsolve(straight_line, guess, args=(m, n))
Also, you have to make sure the x value is the first parameter to straight_line():
defstraight_line(x, m, b):
return m*x + b
I haven't tested this, so it might not be exactly correct. It might not fix all the problems. I suggest you read more tutorials and examples to learn about how this works. Refer to the documentation to be sure you are using fsolve() correctly.
Post a Comment for "Solving Equations With Parameters Python Fsolve"