繁体   English   中英

Python / Sympy三角方程的三角解

[英]Python/Sympy trigonometric solution of cubic equation

我可以使用Python / Sympy获得三次方程的三角符号解吗?

http://en.wikipedia.org/wiki/Casus_irreducibilis http://en.wikipedia.org/wiki/Cubic_function#Trigonometric_.28and_hyperbolic.29_method

更新:现在可以通过在求解这样的等式时使用关键字trig=True with roots或roots_cubic来获得下面给出的解决方案。

这个表单没有给出我知道的任何关键字,但编写例程并不难:

>>> def cutrig(a,b,c,d):
...     a,b,c,d = [S(i) for i in (a,b,c,d)]
...     # x = t - b/3/a
...     p = (3*a*c-b**2)/3/a**2
...     q = (2*b**3-9*a*b*c+27*a**2*d)/(27*a**3)
...     D = 18*a*b*c*d-4*b**3*d+b**2*c**2-4*a*c**3-27*a**2*d**2
...     assert D > 0
...     rv = []
...     for k in range(3):
...         rv.append(2*sqrt(-p/3)*cos(acos(3*q/2/p*sqrt(-3/p))/3-k*2*pi/3))
...     return list(sorted([i - b/3/a for i in rv]))
...
>>> print filldedent(cutrig(-1,2,3,-2))

[-2*sqrt(13)*cos(-acos(8*sqrt(13)/169)/3 + pi/3)/3 + 2/3,
-2*sqrt(13)*sin(-acos(8*sqrt(13)/169)/3 + pi/6)/3 + 2/3, 2/3 +
2*sqrt(13)*cos(acos(8*sqrt(13)/169)/3)/3]
>>> 

与默认的求解解决方案相比:

>>> print filldedent(solve(-x**3+2*x**2+3*x-2))

[2/3 + (-1/2 - sqrt(3)*I/2)*(8/27 + sqrt(237)*I/9)**(1/3) +
13/(9*(-1/2 - sqrt(3)*I/2)*(8/27 + sqrt(237)*I/9)**(1/3)), 2/3 +
13/(9*(-1/2 + sqrt(3)*I/2)*(8/27 + sqrt(237)*I/9)**(1/3)) + (-1/2 +
sqrt(3)*I/2)*(8/27 + sqrt(237)*I/9)**(1/3), 2/3 + 13/(9*(8/27 +
sqrt(237)*I/9)**(1/3)) + (8/27 + sqrt(237)*I/9)**(1/3)]

每个的值都是相同的:

>>> sorted([w.n(2,chop=True) for w in solve(-x**3+2*x**2+3*x-2)])
[-1.3, 0.53, 2.8]
>>> sorted([w.n(2,chop=True) for w in cutrig(-1,2,3,-2)])
[-1.3, 0.53, 2.8]

暂无
暂无

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

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