- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我找不到让 SymPy 将 cos(a)*cos(b)
之类的乘积展开为角和的三角函数之和的方法。
from sympy import *
init_printing()
wrf,wlo,t = symbols('\omega_RF \omega_LO t')
c = cos(wrf*t)*cos(wlo*t)
expand_trig(c)
保持产品完好无损。 simplify(c)
或 trigsimp(c)
也没有给出任何替代形式。
我想将 cos(a)*cos(b)
扩展为 1/2*(cos(a+b) + cos(a-b))
...有什么提示吗?
最佳答案
根据文档字符串,help(sympy.fu)
,
fu
will try to minimize the objective functionmeasure
. By default this first minimizes the number of trig terms and then minimizes the number of total operations.
但是,如果你通过了
measure=lambda x: -x.count_ops()
然后 fu
will try to maximize the op count .
import sympy as sy
sy.init_printing()
wrf, wlo, t = sy.symbols('\omega_RF \omega_LO t')
c = sy.cos(wrf*t)*sy.cos(wlo*t)
print(sy.fu(c, measure=lambda x: -x.count_ops()))
产量
cos(\omega_LO*t - \omega_RF*t)/2 + cos(\omega_LO*t + \omega_RF*t)/2
或者,您可以 call the Fu transformation TR8 directly :
from sympy.simplify.fu import TR8
print(TR8(c))
产生相同的结果。文档字符串 help(sys.modules['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
关于Python3 - 同情 : expand products of trig functions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31104644/
我想在选中复选框时进行设置,然后显示AlertDialog。但有一个问题发生..Eclipse 总是在我的 AlertDialog 下显示一条红线。 new AlertDialog.Builder(s
我知道这是很简单的三角函数,但是我从来没有接触过矢量等,所以我对它的工作原理一头雾水。 给定一个位于 XY 点和 N 方向的物体,您如何沿该方向移动该物体? 此外,给定 XY 点的对象和 XY 点的目
我有一个已知的矩形(灰色)包含图像元素(橙色)的外部父元素。它的溢出是隐藏的。 我想计算允许图像元素(已知宽度和高度)旋转到已知 Angular (例如 30 度)所需的填充。 事实证明,如果我能够允
我正在使用 VS2012 Ultimate 在 C 中进行一些嵌入式开发。我使用平台抽象编译代码并在我的 PC 上模拟它。公司的另一个人使用带有 PPC 抽象层的 CodeWarrior,并在 MPC
我正在寻找计算高度并行化的三角函数(以 1024 为单位),我想至少利用现代架构所具有的一些并行性。 当我编译一个 block 时 for(int i=0; i3 倍的加速)。我敢肯定有人以前遇到过这
我想在标题中传达的是,屏幕上有一个玩家,并且使用方向变量和三角学,他正在“看”一个方向。我需要在他面前生成一个物体。通过生成,我的意思是创建一个 x 和 y 坐标与玩家“前面”的点位置相匹配的对象。
我找不到让 SymPy 将 cos(a)*cos(b) 之类的乘积展开为角和的三角函数之和的方法。 from sympy import * init_printing() wrf,wlo,t = sy
为什么我不必在我的 Perl 程序中使用 use Math::Trig; 来调用 atan2()? 根据 documentation , atan2() 不是“Perl 核心”的一部分。 我有 Per
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 8 年前。 Improve t
我正在修改一个 arcball 类,使其在每次调用 rollforward() 时旋转 1 度。我很难阅读代码,但我相信我需要编写 XY_to_sphere() 的替代方法,其中;设点 1 = v1,
我是一名优秀的程序员,十分优秀!