小编Dar*_*ine的帖子

Python使用numpy曲线与fsolve()和函数参数交叉

我试图在这里引用fsolve:http://glowingpython.blogspot.gr/2011/05/hot-to-find-intersection-of-two.html,

为了找到两条曲线之间的交点.两条曲线基本上都是两个浮点数组.

第一个是一维数组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]
Run Code Online (Sandbox Code Playgroud)

所以我在上面的链接中演示了我实现的findIntersection功能:

def findIntersection(fun1,fun2,x0): 
    return fsolve(lambda x: (fun1(x) - fun2(x,y) for y in range(1,100)),x0)
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

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 …
Run Code Online (Sandbox Code Playgroud)

python numpy intersection curves

6
推荐指数
1
解决办法
6133
查看次数

标签 统计

curves ×1

intersection ×1

numpy ×1

python ×1