turning complex exponential into trigonometric functions

797 views
Skip to first unread message

Colin

unread,
Mar 31, 2010, 11:18:15 AM3/31/10
to sympy
Dear list,
I have expressions coming from my calculation of the type:

(1/45)*3**(1/2)*exp(-1/4*I*k_1 + (1/4)*I*k_2*3**(1/2)) +
(1/45)*3**(1/2)*exp(-1/8*I*k_1 - 1/8*I*k_2*3**(1/2)) +
(1/45)*3**(1/2)*exp((1/4)*I*k_1 - 1/4*I*k_2*3**(1/2)) +
(1/45)*3**(1/2)*exp((1/8)*I*k_1 + (1/8)*I*k_2*3**(1/2)) +
(1/45)*3**(1/2)*exp(-1/4*I*k_1) + (1/45)*3**(1/2)*exp((1/4)*I*k_1)

where k_1,k_2 are real numbers. What is the best way to automatically
rewrite this as a weighted sum of cosines?

all the best
--Colin

Aaron S. Meurer

unread,
Mar 31, 2010, 11:30:09 AM3/31/10
to sy...@googlegroups.com
Use expr.rewrite(cos), as in

In [22]: print a.rewrite(cos)
3**(1/2)*(I*sin(k_1/4) + cos(k_1/4))/45 + 3**(1/2)*(-I*sin(k_1/4) + cos(k_1/4))/45 + 3**(1/2)*(-I*sin(I*(I*k_1/4 - I*k_2*3**(1/2)/4)) + cos(I*(I*k_1/4 - I*k_2*3**(1/2)/4)))/45 + 3**(1/2)*(-I*sin(I*(-I*k_1/4 + I*k_2*3**(1/2)/4)) + cos(I*(-I*k_1/4 + I*k_2*3**(1/2)/4)))/45 + 3**(1/2)*(-I*sin(I*(I*k_1/8 + I*k_2*3**(1/2)/8)) + cos(I*(I*k_1/8 + I*k_2*3**(1/2)/8)))/45 + 3**(1/2)*(I*sin(-I*(-I*k_1/8 - I*k_2*3**(1/2)/8)) + cos(-I*(-I*k_1/8 - I*k_2*3**(1/2)/8)))/45

You could then use expand() to simplify things.

Aaron Meurer

> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To post to this group, send email to sy...@googlegroups.com.
> To unsubscribe from this group, send email to sympy+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
>

Colin

unread,
Mar 31, 2010, 11:52:35 AM3/31/10
to sympy
Great, thanks for this. This is probably implemented in a more recent
version of SymPy than 0.5.15? It's probably time I upgraded my Ubuntu
distribution...

all the best
--Colin

Aaron S. Meurer

unread,
Mar 31, 2010, 12:59:53 PM3/31/10
to sy...@googlegroups.com
Yeah, the most recent version is 0.6.7! I recommend that you upgrade. :)

Aaron Meurer

Ondrej Certik

unread,
Mar 31, 2010, 3:16:27 PM3/31/10
to sy...@googlegroups.com
On Wed, Mar 31, 2010 at 9:59 AM, Aaron S. Meurer <asme...@gmail.com> wrote:
> Yeah, the most recent version is 0.6.7!  I recommend that you upgrade. :)

I have prepared the Debian package for it, but Debian's ftp-master is
down currently, so it will take couple days until they fix it, so that
I can upload it. It will get into Ubuntu eventually too.

Ondrej

Colin

unread,
Apr 15, 2010, 11:27:43 AM4/15/10
to sympy
OK, I have a version that this works for now. Something I noticed is
that there could be simplifications applied inside some of the cos and
sin functions - because of the factor of I. How do you simplify inside
a cos or sin? Alternatively, how do I get the expression with common
factors of I in the exponentials?

all the best
--cjc

On 31 Mar, 16:30, "Aaron S. Meurer" <asmeu...@gmail.com> wrote:

Colin

unread,
Apr 15, 2010, 11:58:54 AM4/15/10
to sympy
On 15 Apr, 16:27, Colin <colinjcot...@gmail.com> wrote:
> OK, I have a version that this works for now. Something I noticed is
> that there could be simplifications applied inside some of the cos and
> sin functions - because of the factor of I. How do you simplify inside
> a cos or sin? Alternatively, how do I get the expression with common
> factors of I in the exponentials?

Ah, don't worry - as_real_imag() does the trick!

--cjc

Reply all
Reply to author
Forward
0 new messages