找到两条曲线的交集。两条曲线基本上都是两个浮动数组。
第一个是一维数组Pmech ( Pmech(x) ),第二个是二维数组Pair ( Pair(x,y) )
x轴对于两个阵列都是通用的,所以我要做的是让每一个y轴都能看到Pair和Pmech相交的地方。
我知道fsolve()采用参数函数,而不是数组,因此我编写了两个基本函数来实现此功能:def Pmix(x):
return Pmech[x]
def Paera(x,y):
return Pair[x,y]
如上面的链接所示,我实现了findIntersection函数:def findIntersection(fun1,fun2,x0):
return fsolve(lambda x: (fun1(x) - fun2(x,y) for y in range(1,100)),x0)
但我得到了以下错误:TypeError: float() argument must be a string or a number
Traceback (most recent call last):
File "batteries.py", line 261, in
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.
最后
以上就是耍酷火龙果最近收集整理的关于python fsolve说明_Python曲线与fsolve()相交,函数参数使用numpy的全部内容,更多相关python内容请搜索靠谱客的其他文章。
发表评论 取消回复