【问题标题】:How to solve equation containing multiple arctan's in python?如何在python中求解包含多个arctan的方程?
【发布时间】:2018-04-12 15:26:29
【问题描述】:

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

-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 不能解决具有多个三角函数的复杂表达式?

【问题讨论】:

  • 尝试 nsolve 得到一个数值近似值。
  • 我尝试过使用 nsolve,但出现“TypeError:无法从 x 创建 mpf”错误或“ValueError:在给定容差范围内找不到根。(32400 > 2.1684e-19) 尝试另一个起点或调整论点。”错误

标签: python-3.x sympy trigonometry control-theory


【解决方案1】:

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

TypeError: cannot create mpf from x

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

【讨论】:

    猜你喜欢
    • 2022-01-17
    • 1970-01-01
    • 1970-01-01
    • 2021-12-22
    • 1970-01-01
    • 2017-02-24
    • 2017-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多