Python scipy 最小化 - 简单示例未产生预期 return

Python scipy minimization - Simple example not producing expected return

我正在尝试使用 scipy 来查找满足简单体积 = 长 * 宽 * 高示例中的条件的变量的最小值。我试图在给定长度 10 和宽度 10 的情况下找到产生 1300 体积的高度。答案应该是 13,但是 scipy 告诉我 x:1.0000044152960563

from scipy.optimize import minimize_scalar

def objective_function(x):
    target = 1300
    length = 10
    width = 10
    (length * width * x) - target
    return x

res = minimize_scalar(objective_function, method='bounded', bounds=(1, 100))
res
print(x)

我可以使用函数外产生的 x 值吗?

我发现我做错了什么。我需要对结果进行平方以获得正数,然后取平方根。

from scipy.optimize import minimize_scalar
import math

def objective_function(x):
    target = 1300
    length = 10
    width = 10
    return (math.sqrt(((length * width * x) - target) ** 2))

res = minimize_scalar(objective_function, method='bounded', bounds=(1, 100))
res.x