等待一个小时后,方程式无法解决
我试图求解一个由两个有两个未知数的方程组成的非线性系统,我尝试使用Sympy模块来完成任务。 在尝试运行下面的代码(On Atom和Google Consoil Notebook)之后,什么也不会发生,并且该过程永远不会终止(等待15分钟)。 有什么问题?我的系统要复杂吗? 我尝试使用Scipy的FSOLVE,并且能够立即获得根源
这是下面的代码
import sympy as sym
sym.init_printing()
x,y = sym.symbols('x,y')
dmin = 70 #minimum of the actuator
dmax = 140 #maximum of the actuator
l3 = 10
l4 = 10
Amin = 0.523599 #min angle in radians
Amax = 2.0944 #max angle in radians
cos1 = sym.cos(Amin - sym.atan(l4/x) - sym.atan(l3/y))
cos2 = sym.cos(Amax - sym.atan(l4/x) - sym.atan(l3/y))
a2 = x**2 + l4**2
b2 = y**2 + l3**2
f=sym.Eq(a2 + b2 - 2*sym.sqrt(a2)*sym.sqrt(b2)*cos1, dmin**2)
g=sym.Eq(a2 + b2 - 2*sym.sqrt(a2)*sym.sqrt(b2)*cos2, dmax**2)
print(sym.solve([f,g],(x,y)))
I was trying to solve a non-linear system that consists of two equations with 2 unknowns, I tried using Sympy module to complete the task.
After trying to run the code below (on Atom and Google Collab notebook), nothing is happening and the process is never terminated (waited for over that 15min).
What could be the problem? is my system to complicated?
I tried to use fsolve from scipy and i was able to get one of the roots in no time
This is the code below
import sympy as sym
sym.init_printing()
x,y = sym.symbols('x,y')
dmin = 70 #minimum of the actuator
dmax = 140 #maximum of the actuator
l3 = 10
l4 = 10
Amin = 0.523599 #min angle in radians
Amax = 2.0944 #max angle in radians
cos1 = sym.cos(Amin - sym.atan(l4/x) - sym.atan(l3/y))
cos2 = sym.cos(Amax - sym.atan(l4/x) - sym.atan(l3/y))
a2 = x**2 + l4**2
b2 = y**2 + l3**2
f=sym.Eq(a2 + b2 - 2*sym.sqrt(a2)*sym.sqrt(b2)*cos1, dmin**2)
g=sym.Eq(a2 + b2 - 2*sym.sqrt(a2)*sym.sqrt(b2)*cos2, dmax**2)
print(sym.solve([f,g],(x,y)))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的方程式类似:
通常是代数和超验功能的混合物,没有任何隔离的解决方案,但是在这种情况下,
cos
可以使用atan
取消,以使纯代代代数纯化方程式:使用此功能,我们可以将系统按摩到一对多项式中,然后用groebner bases求解:
重写为多项式引入虚假解决方案,因此只有其中一些实际上是
f
和g g
g的解决方案。如果您对所需的特定解决方案有初始猜测,则更简单,更快地计算这些解决方案的方法只是使用
nsolde
来数值求解系统:Your equations are like:
Usually a mix of algebraic and transcendental functions like this would not have any anlytic solution but in this case the
cos
can cancel with theatan
to make purely algebraic equations:Using this we can massage the system into a pair of polynomials and then solve it with Groebner bases:
Rewriting as polynomial introduces spurious solutions so only some of those are actually solutions of
f
andg
.A simpler and faster way to compute these solutions if you have an initial guess for a particular solution that you want is just to use
nsolve
to solve the system numerically:这是延续方法的另一个好候选人。讨论是在链接上的,但我将使用
c
进行以下操作,以控制方程的更非线性术语:gs
'
c
转到1成为最终解决方案This is another good candidate for the continuation method. The discussion is at the link but I would apply it as follows using
c
to control the more non-linear term of your equations:gs
starts out asand is gradually modified as
c
goes to 1 to become the final solution