get sympy result as trig function rather than complex log

Viewed 272

I'm doing some manipulation of trig equations and would like the results back in trig form.

What I'm doing is this:

from sympy import *
B,D,a=symbols(r'B,D,alpha',real=True,positive=True)
eq1=Eq(D,B*((sin(a)*sin(a))/(sin(a+a))))
solve(eq1,a)

I expect the result to be atan(2*D/B) but I'm getting:

[-I*log(-sqrt((B + 2*I*D)/(B - 2*I*D))), -I*log((B + 2*I*D)/(B - 2*I*D))/2]

I know sympy is expanding the trig functions into exponential form, but I can't seem to convince it to convert the results back.

I've tried:

[n.rewrite(atan) for n in solve(eq1,a)]

but I get the same result back...

1 Answers

If you simplify before solving, the result looks better.

>>> solve(eq1.simplify(), a)
[atan(2*D/B)]

Also, the more mathematically rigorous solveset (a modern alternative to solve) returns a more mathematically correct answer without the need for simplification:

>>> solveset(eq1, a)
ConditionSet(alpha, Eq(tan(alpha)/2 - D/B, 0), Reals)

The point being that there are infinitely many solutions, so they cannot be given as a list: so, solveset presents them as the set of all alpha such that tan(alpha) is 2*D/B.

Related