我正在使用 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/