How to solve symbolically a pair of nonlinear equations using Python (sympy)?

不羁岁月 提交于 2019-12-12 02:07:50

问题


I have the following code for a system of three nonlinear equations with three unknowns:

import sympy as sp
from sympy import symbols, cos, sin

v0, a0, f0 = symbols('v0 a0 f0')
v1, a1, f1 = symbols('v1 a1 f1')
w, t = symbols('w t')

g1 = v0 + a0 * w * cos(w*t + f0) - v1 - a1 * w * cos(f1)
g2 = v0**2 + a0**2*w**2 -v1**2 - a1**2*w**2
g3 = a0 * sin(w*t + f0) - a1*sin(f1)

sp.solvers.solve((g1,g2,g3), (a1,v1,f1))

The system of equations looks very complicated but actually it is easily solved with Mathematica.

I get the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 487, in runfile
    execfile(filename, namespace)
  File "/home/estudiante/.spyder2/.temp.py", line 16, in <module>
    a0 * sin(w*t + f0) - sin(f1)), (a1,v1,f1))
  File "/usr/lib/python2.7/dist-packages/sympy/solvers/solvers.py", line 484, in solve
    solution = _solve(f, *symbols, **flags)
  File "/usr/lib/python2.7/dist-packages/sympy/solvers/solvers.py", line 730, in _solve
    raise NotImplementedError()
NotImplementedError

I don't know how to fix that, maybe sympy cannot do that. Is there something like sympy which can work? Please help.


回答1:


NotImplementedError means just that, that the algorithms needed to solve the equations are not implemented.

Actually, for me, in the latest version of SymPy (0.7.5), it is able to solve it, so you should upgrade. The solutions are a little complicated, but they're there.



来源:https://stackoverflow.com/questions/22645135/how-to-solve-symbolically-a-pair-of-nonlinear-equations-using-python-sympy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!