【问题标题】:Python3 - Sympy: expand products of trig functionsPython3 - Sympy:扩展三角函数的产品
【发布时间】:2015-09-15 06:21:32
【问题描述】:

我找不到让 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)) ...有什么提示吗?

【问题讨论】:

    标签: python sympy


    【解决方案1】:

    根据文档字符串,help(sympy.fu)

    fu 将尝试最小化目标函数measure。默认情况下这个 首先最小化触发项的数量,然后最小化总的数量 操作。

    但是,如果你通过了

    measure=lambda x: -x.count_ops()
    

    然后fuwill 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-24
      • 1970-01-01
      • 1970-01-01
      • 2022-01-19
      • 2013-07-05
      相关资源
      最近更新 更多