# 尝试计算笛卡尔系统中未知坐标的位置时形状不匹配

##### 问题描述投票：0回答：1

TypeError：fsolve：输入和输出之间不匹配 “func”参数“unknown_point_equations”的形状。形状应该是 (2,) 但它是 (3,)。

``````import numpy as np
from scipy.optimize import fsolve

def unknown_point_equations(variables, x1, y1, d1, x2, y2, d2, x3, y3, d3):
x, y = variables
eq1 = (x - x1)**2 + (y - y1)**2 - d1**2
eq2 = (x - x2)**2 + (y - y2)**2 - d2**2
eq3 = (x - x3)**2 + (y - y3)**2 - d3**2
return [eq1, eq2, eq3]

def calculate_unknown_point(x1, y1, d1, x2, y2, d2, x3, y3, d3):
# Initial guess for the unknown point
initial_guess = [0, 0]

# Solve the system of equations
result, infodict, ier, msg = fsolve(unknown_point_equations, initial_guess, args=(x1, y1, d1, x2, y2, d2, x3, y3, d3), full_output=True)

if ier != 1:
raise RuntimeError(f"fsolve did not converge: {msg}")

# Extract the coordinates of the unknown point
x_p, y_p = result[0], result[1]

return x_p, y_p
``````

``````x1, y1, d1 = 324,300,147

x2, y2, d2 = 278,414,224

x3, y2, d3, = 357,437,276
``````
python math
##### 1个回答
0

``````initial_guess = [0, 0]
``````

``unknown_point_equations``

``````[eq1, eq2, eq3]
``````

``fsolve``

``[0, 0, 0]``
，你不应该对第三个变量做任何事情。狩猎快乐！

``````import numpy as np
from scipy.optimize import fsolve

def unknown_point_equations(variables, x1, y1, d1, x2, y2, d2, x3, y3, d3):
x, y, _ = variables
eq1 = (x - x1)**2 + (y - y1)**2 - d1**2
eq2 = (x - x2)**2 + (y - y2)**2 - d2**2
eq3 = (x - x3)**2 + (y - y3)**2 - d3**2
return [eq1, eq2, eq3]

def calculate_unknown_point(x1, y1, d1, x2, y2, d2, x3, y3, d3):
# Initial guess for the unknown point
initial_guess = [0, 0, 0]

# Solve the system of equations
result, infodict, ier, msg = fsolve(
unknown_point_equations,
initial_guess,
args=(x1, y1, d1, x2, y2, d2, x3, y3, d3),
full_output=True
)

if ier != 1:
raise RuntimeError(f"fsolve did not converge: {msg}")

# Extract the coordinates of the unknown point
x_p, y_p, _ = result

return x_p, y_p
``````

（尽管如此，就其价值而言，它对于您提供的值并不收敛。您需要一个不同的起点。）