python - 方程根 : parameter doesn't get simplified

标签 python parameters equation sympy

我正在使用 Python 和 Sympy。

我需要解下面的方程,找到 4 个根(omega 是我的未知数):

deter= 0.6*omega**4*cos(omega*t)**2 - 229.0*omega**2*cos(omega*t)**2 + 5880.0*cos(omega*t)**2

我尝试使用解决:

eqcarr=solve(deter,omega,exclude=[t])

我得到这个输出:

[-18.8143990830350, -5.26165884593044, 5.26165884593044, 18.8143990830350, 1.5707963267949/t, 4.71238898038469/t]

我只需要前 4 个值,而不需要带有 t 系数的值。我希望 cos(omega*t)**2 在求解中得到简化,但这并没有发生。

最佳答案

根据文档solve将不会解析exclude中传递的任何自由符号。

'exclude=[] (default)' don't try to solve for any of the free symbols in exclude; if expressions are given, the free symbols in them will be extracted automatically.

它不是为了过滤溶液。

您可以通过这样做来解决您的问题:

In [10]: from sympy import *
In [11]: from sympy.abc import omega, t
In [12]: deter= 0.6*omega**4*cos(omega*t)**2 - 229.0*omega**2*cos(omega*t)**2 + 5880.0*cos(omega*t)**2

In [13]: eqcarr=solve(deter,omega,exclude=[t])

In [14]: filtered = [i for i in eqcarr if not i.has(t)]
In [15]: filtered
Out[15]: [-18.8143990830350, -5.26165884593044, 5.26165884593044, 18.8143990830350]

关于python - 方程根 : parameter doesn't get simplified,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24424909/

相关文章:

python - 如何在Python中找到一条直线和多条曲线的交点?

c - 数值稳定正向替换

python - 用Python求解非线性方程组

python - Python 中的 FTP_ASCII

python - Tornado 下一个查询字符串 URL 参数

ios - 通过带有参数的 Siri 启动应用程序,无需捐赠/快捷方式

php - 如何将 stream_socket_client 绑定(bind)到 php 中的接口(interface)?

python - 在pyqt中模拟鼠标移动

python - 使用 Rapids.ai 0.11+ 版将 cuDF 和 cuML 安装到 Colab

python - 'NoneType' 对象没有属性 'add'