Simplifying complex expressions

33 views
Skip to first unread message

PG

unread,
Jul 9, 2015, 5:24:57 PM7/9/15
to sy...@googlegroups.com
Hi,

SymPy does not seem to be able to simplify the following expression:

a = Symbol('a')
simplify((2+2*I)*exp(I*a) +(2-2*I)*exp(-I*a))

Is there a workaround?

Thanks!

PG

Gaurav Dhingra

unread,
Jul 10, 2015, 2:36:38 PM7/10/15
to sy...@googlegroups.com
Hi PG

Though you should what output you expect(that helps the answerer). Assuming you expect solution in terms of `sin` or `cos` or some trigonometry. You can fo this:
```
>>> expr = (2+2*I)*exp(I*a) - (2-2*I)*exp(-I*a)
>>> simplify(expr.rewrite(sin))
4*sqrt(2)*I*sin(a+pi/4)
```

Cheers
Gaurav

Pavel Grinfeld

unread,
Jul 10, 2015, 2:58:36 PM7/10/15
to sy...@googlegroups.com
Hey, thanks a lot, but that doesn't seem right since the solution should have a real and imaginary part!

Thanks again,

Pavel

Gaurav

--
You received this message because you are subscribed to a topic in the Google Groups "sympy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sympy/tDzSVoYz2m8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/dc71e2c2-49fb-4b2d-ad49-696c70d72101%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gaurav Dhingra

unread,
Jul 10, 2015, 3:50:21 PM7/10/15
to sy...@googlegroups.com
Since the real part is zero in this case. Hence only imaginary part is there, which I guess is given correctly. In the answer.
Isn't it ?

Pavel Grinfeld

unread,
Jul 10, 2015, 5:02:58 PM7/10/15
to sy...@googlegroups.com
Yes, you are right, I think I mistyped the original question. So let me try to save it from here: is there a way to get the answer as a linear combination of sin and cos?



On Fri, Jul 10, 2015 at 3:50 PM, Gaurav Dhingra <axyd...@gmail.com> wrote:
Since the real part is zero in this case. Hence only imaginary part is there, which I guess is given correctly. In the answer.
Isn't it ?
--
You received this message because you are subscribed to a topic in the Google Groups "sympy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sympy/tDzSVoYz2m8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sympy+un...@googlegroups.com.
To post to this group, send email to sy...@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.

Aaron Meurer

unread,
Jul 10, 2015, 6:52:17 PM7/10/15
to sy...@googlegroups.com
If you use expand(trig=True) on the expression it will expand the
trigonometric functions.

Aaron Meurer
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/CAAnX_%3DR5%3DK%2B3huAvkPDy87Qc%2BOD3DeG4RjoFD%3DkR%2B4rLi6TxNQ%40mail.gmail.com.

Pavel Grinfeld

unread,
Jul 10, 2015, 11:20:00 PM7/10/15
to sy...@googlegroups.com
I do not believe that is the case:

>>> expand((2+3*I)*exp(2*I) + (2-3*I)*exp(-2*I), sin, trig=True)
2*exp(-2*I) + 3*I*exp(2*I) - 3*I*exp(-2*I) + 2*exp(2*I)

Sartaj Singh

unread,
Jul 10, 2015, 11:36:23 PM7/10/15
to sy...@googlegroups.com
You should do this.

>>> ((2+2*I)*exp(I*x) + (2-2*I)*exp(-I*x)).rewrite(sin).expand(sin,trig=True)
-4*sin(x) +4*cos(x)

Pavel Grinfeld

unread,
Jul 10, 2015, 11:41:26 PM7/10/15
to sy...@googlegroups.com
That's almost it! Thank you.
Could I have the answer as a trig polynomial, meaning sin(2a) instead of sin(a)cos(a), etc.

Thanks again.

Sartaj Singh

unread,
Jul 10, 2015, 11:43:03 PM7/10/15
to sy...@googlegroups.com
Trigsimp should do it.

>>> trigsimp(sin(x)*cos(x))
sin(2*x)/2


For more options, visit https://groups.google.com/d/optout.



--
Regards
Sartaj Singh

Mathematics and Computing,
Indian Institute of Technology,
Varanasi - 221 005 INDIA

Reply all
Reply to author
Forward
0 new messages