sympy:三角和积恒等式 [英] sympy: trigonometric sum-product identities
问题描述
我有一个表达式:sin(x)+sin(y)
有一个众所周知的三角恒等式将其表示为 sin 和 cos 的乘积.
There is a well-known trig identity to express this as the product of sin and cos.
有没有办法让同情来应用这个身份?
Is there a way to get sympy to apply this identity?
simplify
和 trigsimp
什么都不做.
推荐答案
trigsimp
,正如 Aristocrates 指出的,正好相反,因为 sin(x) + sin(y)
比 2*sin((x + y)/2)*cos((x - y)/2)
简单.
trigsimp
, as Aristocrates points out, does the reverse, because sin(x) + sin(y)
is simpler than 2*sin((x + y)/2)*cos((x - y)/2)
.
trigsimp
在内部使用基于 傅等.al.,它对各种三角恒等式进行模式匹配.如果你查看源代码,所有的身份写在单独的函数中(函数以傅的论文中的部分命名).
trigsimp
internally uses an algorithm based on a paper by Fu, et. al., which does pattern matching on various trigonometric identities. If you look at the source code, all the identities are written out in individual functions (the functions are named after the sections in Fu's paper).
查看文件顶部的简化列表,您想要的可能是
Looking at the list of simplifications at the top of the file, the one you want is probably
TR9 - contract sums of sin-cos to products
测试了一下,好像可以使用
Testing it out, it looks like it works
In [1]: from sympy.simplify.fu import TR9
In [2]: TR9(sin(x) + sin(y))
Out[2]:
⎛x y⎞ ⎛x y⎞
2⋅sin⎜─ + ─⎟⋅cos⎜─ - ─⎟
⎝2 2⎠ ⎝2 2⎠
我们最终希望将这些分解为更用户友好的函数,但就目前而言,fu.py
文件已被很好地记录下来,即使所有函数名称都不是特别容易记住.
We would eventually like to factor these out into more user-friendly functions, but for now, the fu.py
file is pretty well documented, even if all the function names are not particularly memorable.
这篇关于sympy:三角和积恒等式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!