如何使用 Python (sympy) 象征性地求解一对非线性方程? [英] How to solve symbolically a pair of nonlinear equations using Python (sympy)?

查看:50
本文介绍了如何使用 Python (sympy) 象征性地求解一对非线性方程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于包含三个未知数的三个非线性方程组,我有以下代码:

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))

方程组看起来很复杂,但实际上用 Mathematica 很容易解决.

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

我收到以下错误:

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

我不知道如何解决这个问题,也许 sympy 无法做到这一点.有没有像 sympy 这样的东西可以工作?请帮忙.

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

推荐答案

NotImplementedError 只是意味着,求解方程所需的算法没有实现.

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

其实对我来说,在最新版本的SymPy(0.7.5)中已经可以解决了,所以你应该升级.解决方案有点复杂,但它们就在那里.

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.

这篇关于如何使用 Python (sympy) 象征性地求解一对非线性方程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆