2

我需要为控制系统课程求解以下方程;

-atan((sqrt(319)*x/9 - 4)/(x - 2)) - atan((sqrt(319)*x/9 + 4)/(x - 2)) + atan(sqrt(319)*x/(9*(x + 2))) + atan(sqrt(319)*x/(9*(x + 4))) + 180 = 0

我尝试使用以下 python 程序来确定 x 的值;

import numpy as np
import sympy as sy
sy.init_printing()

x = sy.symbols('x')

sy.solve(sy.atan(((sy.sqrt(319)/9)*x)/(x + 2)) + sy.atan(((sy.sqrt(319)/9)*x)/(x + 4)) - sy.atan((((sy.sqrt(319)/9)*x) + 4)/(x - 2)) - sy.atan((((sy.sqrt(319)/9)*x) - 4)/(x - 2)) + 180, x)

但我不断收到以下错误;

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-2-52038f2d514c> in <module>()
      5 x = sy.symbols('x')
      6 
----> 7 sy.solve(sy.atan(((sy.sqrt(319)/9)*x)/(x + 2)) + 
sy.atan(((sy.sqrt(319)/9)*x)/(x + 4)) - sy.atan((((sy.sqrt(319)/9)*x) + 4)/(x - 2)) - sy.atan((((sy.sqrt(319)/9)*x) - 4)/(x - 2)) + 180, x)

C:\ProgramData\Anaconda3\lib\site-packages\sympy\solvers\solvers.py in solve(f, *symbols, **flags)
   1063     
###########################################################################
   1064     if bare_f:
-> 1065         solution = _solve(f[0], *symbols, **flags)
   1066     else:
   1067         solution = _solve_system(f, symbols, **flags)

C:\ProgramData\Anaconda3\lib\site-packages\sympy\solvers\solvers.py in _solve(f, *symbols, **flags)
   1632 
   1633     if result is False:
-> 1634         raise NotImplementedError('\n'.join([msg, not_impl_msg % f]))
   1635 
   1636     if flags.get('simplify', True):

NotImplementedError: multiple generators [atan(sqrt(319)*x/(9*(x + 2))), atan(sqrt(319)*x/(9*(x + 4))), atan(sqrt(319)*x/(9*(x - 2)) + 4/(x - 2)), atan(sqrt(319)*x/(9*(x - 2)) - 4/(x - 2))]
No algorithms are implemented to solve equation -atan((sqrt(319)*x/9 - 4)/(x - 2)) - atan((sqrt(319)*x/9 + 4)/(x - 2)) + atan(sqrt(319)*x/(9*(x + 2))) + atan(sqrt(319)*x/(9*(x + 4))) + 180

有没有办法解决这个问题,或者 Python 不能解决具有多个三角函数的复杂表达式?

4

1 回答 1

0

我遇到了同样的问题,找不到解决该错误的方法:

TypeError: cannot create mpf from x

相反,因为这是三角函数,如果您使用度数,答案必须在 0 - 360 范围内。我使用 for 循环遍历这个范围并返回一个近似解。

于 2019-05-18T22:57:23.270 回答