简体   繁体   English

如何使用 Sympy 求解 x - a tan(x) = 0

[英]How to solve x - a tan(x) = 0 with Sympy

I'm trying to find a solution to the equation我试图找到方程的解

x = a * tan (x)

on Python.在 Python 上。 Sympy seems to be able to solve this kind of equation so if I write Sympy 似乎能够解决这种方程,所以如果我写

import sympy as sym
x = sym.Symbol('x')
sym.solveset(x/sym.tan(x) - 0.5, x)

I get the output:我得到输出:

{ x ∣ x∈C ∧ x − 0.5*tan(x) = 0 } ∖ ({ 2nπ | n∈Z } ∪ { 2nπ+π | n∈Z })

I know there are 3 solutions for every tangent cycle, and I don't understand what Sympy is telling me.我知道每个切线循环都有 3 个解决方案,我不明白 Sympy 在告诉我什么。

I would expect to find something similar to this:我希望找到类似的东西:

graphs of y=0.5*tan(x) and y=x y=0.5*tan(x) 和 y=x 的图形

The output means "the set of all values that set the equation to zero excluding certain values involving pi."输出意味着“将方程设置为零的所有值的集合,不包括涉及 pi 的某些值。” I don't think you will find a closed form solution for this but you can get numerical answers.我认为您不会为此找到封闭形式的解决方案,但您可以获得数字答案。 Consider rewriting to make it better behaved:考虑重写以使其表现更好:

>>> [nsolve(sin(x)-2*cos(x)*x, i).round(2) for i in (0,2,4)]
[0, 1.17, 4.6]

If you look at a plot of this you will see there are an infinite number of solutions;如果你看一下这个图,你会发现有无数个解决方案; these are only 3 non-negative ones.这些只是 3 个非负数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM