我的代码如下(我怀疑您是否需要全部代码,但我已经提供了所有代码):
import numpy
from scipy import fsolve
from dataclasses import dataclass
@dataclass
class Localize:
receivers: list
@staticmethod
def equations(p, *times):
x, y, z, t = p
t0, t1, t2, t3, \
ax, ay, az, \
bx, by, bz, \
cx, cy, cz, \
dx, dy, dz, \
c = times
F = numpy.empty((4))
F[0] = (ax - x) ** 2 + (ay - y) ** 2 \
+ (az - z) ** 2 - c(t0 - t)
F[1] = (bx - x) ** 2 + (by - y) ** 2 \
+ (bz - z) ** 2 - c(t1 - t)
F[2] = (cx - x) ** 2 + (cy - y) ** 2 \
+ (cz - z) ** 2 - c(t2 - t)
F[3] = (dx - x) ** 2 + (dy - y) ** 2 \
+ (dz - z) ** 2 - c(t3 - t)
return F
@staticmethod
def sanityCheck(times):
# Check for valid input
print('whoo')
@staticmethod
def find(self, times):
times.append(self.receivers)
initial = numpy.array([0,0,0,0])
return fsolve(self.equations, initial, args = tuple(times))
local = Localize(1,1,1,1,1,1,1,1,1)
local.find(1,2,3,4)
我通过运行以下命令验证了我确实有一个正常运行的SciPy
安装:
>>> import scipy
>>> scipy.__version___
'1.5.3'
>>>
它抛出了一个错误:
From scipy import fsolve ImportError: cannot import name 'fsolve' from 'scipy'
我试着用标准的Python
解释器和PyCharm
运行这个程序,但没有成功
您可以从优化库导入fsolve函数
试用:
相关问题 更多 >
编程相关推荐