用渐近非线性解法找不到非线性方程组的解

问题描述

我有一个非线性系统,我正在尝试使用SUNNY来求解。该系统描述为:

-5.5*c_1*c_2 - 5.0*c_1 + 5.5*s_1*s_2 + 5.5
-5.5*c_1*s_2 - 5.5*c_2*s_1 - 5.0*s_1
c_1**2 + s_1**2 - 1.0
c_2**2 + s_2**2 - 1.0

运行sympy.solve(system, variables, domain=sympy.S.Reals, dict=True),返回以下解决方案:

{s_1: -0.890723542830247, s_2: 0.890723542830247, c_1: 0.454545454545455, c_2: -0.454545454545455}
{s_1: 0.890723542830247, s_2: -0.890723542830247, c_1: 0.454545454545455, c_2: -0.454545454545455}

但是,当运行sympy.nonlinsolve(system, variables)时,不返回任何解决方案。

为什么symmy.ynlinsolve找不到此非线性系统的解?

是否有其他我应该改为运行的函数?

对于上下文,我正在努力解决robotics inverse kinematics problem using symbolic algebra

可重现代码:

# python3.6

import sympy
from sympy import Symbol as Sym

s_1, s_2, c_1, c_2 = Sym("s_1", real=True), Sym("s_2", real=True), Sym("c_1", real=True), Sym("c_2", real=True)

p1 = -5.5*c_1*c_2 - 5.0*c_1 + 5.5*s_1*s_2 + 5.5
p2 = -5.5*c_1*s_2 - 5.5*c_2*s_1 - 5.0*s_1
p3 = 1.0*c_1**2 + 1.0*s_1**2 - 1.0
p4 = 1.0*c_2**2 + 1.0*s_2**2 - 1.0

system = [p1, p2, p3, p4]
variables = [s_1, s_2, c_1, c_2]

# {s_1: -0.890723542830247, s_2: 0.890723542830247, c_1: 0.454545454545455, c_2: -0.454545454545455}
# {s_1: 0.890723542830247, s_2: -0.890723542830247, c_1: 0.454545454545455, c_2: -0.454545454545455}
sols = sympy.solve(system, variables, domain=sympy.S.Reals, dict=True)

print(f"{len(sols)} solutions")
for sol in sols:
    print(sol)

# 0 solutions
sols = sympy.nonlinsolve(system,  variables)

print(f"{len(sols)} solutions")
for sol in sols:
    print(sol)

解决方案

如果您遵循错误消息的建议(至少在我使用的版本中),并将原始公式(公式)中的浮点数更改为有理数,您将获得解决方案:

>>> eqs=[nsimplify(i, rational=1) for i in eqs]
>>> ans = nonlinsolve(eqs,list(Tuple(*eqs).free_symbols))
>>> [[j.n(2) for j in i] for i in ans]
[[0.45, -0.45, -0.89, 0.89], [0.45, -0.45, 0.89, -0.89]]

相关文章