MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: real and imaginary part of a complex number

  • To: mathgroup at smc.vnet.net
  • Subject: [mg108542] Re: [mg108521] real and imaginary part of a complex number
  • From: Leonid Shifrin <lshifr at gmail.com>
  • Date: Mon, 22 Mar 2010 02:41:16 -0500 (EST)
  • References: <201003210707.CAA19898@smc.vnet.net>

Hi Khayrul,

How hard this is going to be will depend on the complexity of your
expressions. One good function to use is ComplexExpand.  It assumes that all
symbols in an expression are real, unless explicitly specified otherwise.

Here is a simple example. Given this  expression

In[884]:= expr = (a*z1)^2*Exp[b*z2^2]

Out[884]= a^2 E^(b z2^2) z1^2

Here is how it is expanded:

In[896]:= expanded = ComplexExpand[expr , {z1, z2}]

Out[896]= -a^2 E^(b (-Im[z2]^2 + Re[z2]^2))
   Cos[2 b Im[z2] Re[z2]] Im[z1]^2 +
 a^2 E^(b (-Im[z2]^2 + Re[z2]^2)) Cos[2 b Im[z2] Re[z2]] Re[z1]^2 -
 2 a^2 E^(b (-Im[z2]^2 + Re[z2]^2))
   Im[z1] Re[z1] Sin[2 b Im[z2] Re[z2]] +
 I (2 a^2 E^(b (-Im[z2]^2 + Re[z2]^2))
      Cos[2 b Im[z2] Re[z2]] Im[z1] Re[z1] -
    a^2 E^(b (-Im[z2]^2 + Re[z2]^2)) Im[z1]^2 Sin[2 b Im[z2] Re[z2]] +
     a^2 E^(b (-Im[z2]^2 + Re[z2]^2)) Re[z1]^2 Sin[2 b Im[z2] Re[z2]])

Note that we indicated explicitly all variables which are to be considered
complex. You can form the equation you are interested in, for example as
follows:

In[901]:= Assuming[{Element[{a, b}, Reals]},
 Simplify[Re[expanded]] == Simplify[Im[expanded]]]

We had to Simplify under the above assumptions since for most  simplifiers
in Mathematica (Simplify included), the default assumption is opposite to
that of ComplexExpand - namely that any variable or sub-expression is
complex unless explicitly stated otherwise.

Out[901]= -a^2 E^(
  b (-Im[z2]^2 + Re[z2]^2)) (Cos[2 b Im[z2] Re[z2]] Im[z1]^2 -
    Cos[2 b Im[z2] Re[z2]] Re[z1]^2 +
    2 Im[z1] Re[z1] Sin[2 b Im[z2] Re[z2]]) ==
 a^2 E^(b (-Im[z2]^2 +
     Re[z2]^2)) (2 Cos[2 b Im[z2] Re[z2]] Im[z1] Re[z1] -
    Im[z1]^2 Sin[2 b Im[z2] Re[z2]] + Re[z1]^2 Sin[2 b Im[z2] Re[z2]])

Sometimes it can be simplified further, but this can take a really long time
for a large expression:

In[902]:= Assuming[{Element[{a, b}, Reals]},
 Simplify[Re[expanded] == Im[expanded]]]


Out[902]=
a (Im[z1]^2 (Cos[2 b Im[z2] Re[z2]] - Sin[2 b Im[z2] Re[z2]]) +
    Re[z1]^2 (-Cos[2 b Im[z2] Re[z2]] + Sin[2 b Im[z2] Re[z2]]) +
    2 Im[z1] Re[
      z1] (Cos[2 b Im[z2] Re[z2]] + Sin[2 b Im[z2] Re[z2]])) == 0


Hope this helps.

Regards,
Leonid




On Sun, Mar 21, 2010 at 12:07 AM, Khayrul Hasan <khayrulmat at yahoo.com>wrote:

> Dear Sir
>
> Could you please help me to equate real and imaginary part of a very very
> long complex expression?
>
>  With kindest regards,
>
>
> M. Khayrul Hasan
> Assistant Professor
> Department of Mathematics
> Shahjalal University of Science & Technology
> Sylhet-3100
> Bangladesh
> Cell: 008801716284646
>


  • Prev by Date: Re: Re: Butterworth filter
  • Next by Date: Re: Rings on a matrix
  • Previous by thread: Re: real and imaginary part of a complex number
  • Next by thread: Re: real and imaginary part of a complex number