2015-06-28 7 views
5

Nie mogę znaleźć sposobu, aby SymPy rozszerzyć produkty takie jak cos(a)*cos(b) na sumę funkcji wyzwalania sumy kątów.Python3 - Sympy: rozwiń produkty funkcji trygonowych

from sympy import * 
init_printing() 
wrf,wlo,t = symbols('\omega_RF \omega_LO t') 
c = cos(wrf*t)*cos(wlo*t) 
expand_trig(c) 

Utrzymuje produkt w stanie nienaruszonym. simplify(c) lub trigsimp(c) również nie dają żadnej alternatywnej formy.

Chciałbym, aby cos(a)*cos(b) został rozszerzony do 1/2*(cos(a+b) + cos(a-b)) ... żadnych wskazówek?

Odpowiedz

8

Per na docstring, help(sympy.fu),

fu postara się zminimalizować funkcję celu measure. Domyślnie ten najpierw minimalizuje liczbę terminów wyzwalania, a następnie minimalizuje liczbę wszystkich operacji .

Jeśli jednak zdać

measure=lambda x: -x.count_ops() 

następnie 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())) 

daje

cos(\omega_LO*t - \omega_RF*t)/2 + cos(\omega_LO*t + \omega_RF*t)/2 

Alternatywnie, można call the Fu transformation TR8 directly:

from sympy.simplify.fu import TR8 
print(TR8(c)) 

daje ten sam rezultat. Docstring, help(sys.modules['sympy.simplify.fu']) wyjaśnia dostępne transformacje. Oto podsumowanie; sprawdź dokumentację, aby uzyskać więcej informacji:

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