三角恒等式

6

我有一个同时包含正弦和余弦的表达式,想要仅使用正弦(或余弦)来书写它,可能需要使用幂次降幂公式

我尝试使用SymPy,但无法将其“重写”为所需的输出:

angle = symbols('angle')
print (sin(angle)**2).rewrite(sin, cos) # (1 - cos(2*angle))/2
print ((1 - cos(2*angle))/2).rewrite(cos, sin) # sin(angle)**2

有没有办法告诉Sympy只使用正弦(或余弦)重新编写这样的表达式?
1个回答

4

sympy.simplify.fu模块基于三角恒等式定义了许多变换。

TR0 - simplify expression
TR1 - sec-csc to cos-sin
TR2 - tan-cot to sin-cos ratio
TR2i - sin-cos ratio to tan
TR3 - angle canonicalization
TR4 - functions at special angles
TR5 - powers of sin to powers of cos
TR6 - powers of cos to powers of sin
TR7 - reduce cos power (increase angle)
TR8 - expand products of sin-cos to sums
TR9 - contract sums of sin-cos to products
TR10 - separate sin-cos arguments
TR10i - collect sin-cos arguments
TR11 - reduce double angles
TR12 - separate tan arguments
TR12i - collect tan arguments
TR13 - expand product of tan-cot
TRmorrie - prod(cos(x*2**i), (i, 0, k - 1)) -> sin(2**k*x)/(2**k*sin(x))
TR14 - factored powers of sin or cos to cos or sin power
TR15 - negative powers of sin to cot power
TR16 - negative powers of cos to tan power
TR22 - tan-cot powers to negative powers of sec-csc functions
TR111 - negative sin-cos-tan powers to csc-sec-cot

我从这篇帖子asmeurer的这篇文章中了解了这些函数。


import sympy as sy
from sympy import sin, cos
FU = sy.FU

angle = sy.symbols('angle')
expr = sin(angle)**2

print(FU['TR8'](expr))
# -cos(2*angle)/2 + 1/2

print(FU['TR5'](expr))
# -cos(angle)**2 + 1

非常感谢您详尽的回答,这真的太棒了! - Ecir Hana
你可以直接使用 import sympy.simplify.fu as FU - asmeurer
其实,我猜你做不到。Python的导入机制很奇怪。 - asmeurer
但是你可以使用 from sympy import FU,这将为您提供一个函数字典。 - asmeurer

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接