简体   繁体   中英

Exponential to trigonometric conversion in SymPy while simplifying - a stubborn expression

I have been trying to simplify

exp(2*I*N) - 1)**2/((exp(2*I*N) - 1)**2 - 4*exp(2*I*N)*cos(N)**2)

Where the answer should be (sin N)^2, but the output is same as input.

I have tried .rewrite(cos) and then simplify, trigsimp, expand and pretty much all I could discover quickly from help sources.

Rewriting in terms of exp instead of cos is more helpful:

expr.rewrite(exp).simplify()

returns -cos(2*N)/2 + 1/2 which is visibly equivalent to sin(N)**2 . Clean it up with

expr.rewrite(exp).simplify().trigsimp()

getting sin(N)**2


Old answer, might still be of value: You probably meant N to be real, so let's declare it as such.

Given a mix of complex exponentials and trigonometric functions, it will probably help to separate the real and imaginary parts with as_real_imag() . A direct application does not do much beyond putting re(...) and im(...), so rewriting in exponentials and expanding the squares/products is advisable first:

N = symbols('N', real=True)
expr = (exp(2*I*N) - 1)**2/((exp(2*I*N) - 1)**2 - 4*exp(2*I*N)*cos(N)**2)
result = [a.trigsimp() for a in expr.rewrite(cos).expand().as_real_imag()]

Result: [sin(N)**2, 0] , meaning the real and imaginary parts of the expression. It can be recombined into a single expression with result[0] + I*result[1] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM