I am trying to use fsolve as quoted here : http://glowingpython.blogspot.gr/2011/05/hot-to-find-intersection-of-two.html,
On order to find the intersection between two curves. Both curves basically are two arrays of floats.
The first of them is a one dimension array Pmech ( Pmech(x) )
and the second is a two dimension array Pair ( Pair(x,y) )
The x - axis is common for both arrays ,so what i want to do is for every y to see where Pair and Pmech intersect.
I am aware of the fact that fsolve()
take as arguments functions, not arrays so I wrote two basic functions to implement this feature:
def Pmix(x):
return Pmech[x]
def Paera(x,y):
return Pair[x,y]
So as demonstrated in the above link I implemented the findIntersection
function :
def findIntersection(fun1,fun2,x0):
return fsolve(lambda x: (fun1(x) - fun2(x,y) for y in range(1,100)),x0)
but I get the following error :
TypeError: float() argument must be a string or a number
Traceback (most recent call last):
File "batteries.py", line 261, in <module>
findIntersection(Pmix,Paera,0)
File "batteries.py", line 238, in findIntersection
fsolve(lambda x: (fun1(x) - fun2(x,y) for y in range(1,100) ),x0)
File "/usr/lib/python2.7/dist-packages/scipy/optimize/minpack.py", line 125, in fsolve
maxfev, ml, mu, epsfcn, factor, diag)
minpack.error: Result from function call is not a proper array of floats.