【发布时间】:2020-04-17 21:24:31
【问题描述】:
我的符号都是真实创建的(使用real=True)。如果我使用nonlinsolve 来解决x_1^2+1 我正确地没有得到任何解决方案。然而,更复杂的方程组会导致虚解。我是否误解了nonlinsolve 的工作原理?
# Create real symbols x_1,x_2,...,x_18
syms = [Symbol('x_{}'.format(i), real=True) for i in range(1,19)]
for i,s in enumerate(syms):
exec('x_{} = syms[{}]'.format(i+1, i))
# This code respects the real attribute
test = [Eq(eq) for eq in [x_1*x_1+1]]
print(nonlinsolve(test, x_1))
# This code violates the real attribute and gives imaginary solutions
test = [Eq(eq) for eq in [36*x_1 + 15*x_18**3 - 50*x_18**2 + 6*x_18 - 4, 15*x_18**3 - 50*x_18**2 + 114*x_18 + 36*x_2 - 40, -15*x_18**3 + 50*x_18**2 - 54*x_18 + 12*x_3 + 28, x_4 + 1, -x_18 + x_5, x_6 - 1, -15*x_18**3 + 50*x_18**2 - 42*x_18 + 36*x_7 + 4, 15*x_18**3 - 50*x_18**2 + 6*x_18 + 36*x_8 - 4, 15*x_18**3 - 50*x_18**2 + 54*x_18 + 12*x_9 - 16, x_10 - 3*x_18 + 2, x_11 - 1, x_12 + x_18 - 1, 36*x_13 + 15*x_18**3 - 50*x_18**2 + 114*x_18 - 76, x_14 + 1, 18*x_15 - 15*x_18**3 + 50*x_18**2 - 24*x_18 + 4, 6*x_16 + 15*x_18**3 - 50*x_18**2 + 54*x_18 - 22, x_17 + 2*x_18 - 1, 15*x_18**4 - 20*x_18**3 + 14*x_18**2 + 8*x_18 - 8]]
print(nonlinsolve(test, syms))
【问题讨论】:
-
我在 sympy master 上尝试了您的示例,并得到了一个我认为是错误的异常:github.com/sympy/sympy/issues/19144