
Re: How to get the Real and Imaginary part of an expression
Posted:
Jan 5, 2013 2:18 AM


Dear All
Many thanks for the answers. I have adapted some of them to my needs.
Cheers
Ed
On Jan 3, 2013, at 12:37 PM, Murray Eisenberg <murrayeisenberg@gmail.com> wrote:
> And one more thing, > > If you wish to get fancy with this, you can extract both the real and imaginary parts at once: > > ComplexExpand[Through[{Re, Im}[(w)/(s^2 + 2*z*w*s + w^2)]], s] > > On Jan 3, 2013, at 9:28 AM, Murray Eisenberg <murrayeisenberg@gmail.com> wrote: > >> I forgot that ComplexExpand can take an optional 2nd argument specifying any variables that should be treated as complex rather than as real. Hence you can also do the following (again with results shown in InputForm): >> >> ComplexExpand[Re[(w)/(s^2 + 2*z*w*s + w^2)], s] >> w^3/((2*w*z*Im[s] + 2*Im[s]*Re[s])^2 + (w^2  Im[s]^2 + 2*w*z*Re[s] + Re[s]^2)^ >> 2)  (w*Im[s]^2)/((2*w*z*Im[s] + 2*Im[s]*Re[s])^2 + >> (w^2  Im[s]^2 + 2*w*z*Re[s] + Re[s]^2)^2) + >> (2*w^2*z*Re[s])/((2*w*z*Im[s] + 2*Im[s]*Re[s])^2 + >> (w^2  Im[s]^2 + 2*w*z*Re[s] + Re[s]^2)^2) + >> (w*Re[s]^2)/((2*w*z*Im[s] + 2*Im[s]*Re[s])^2 + >> (w^2  Im[s]^2 + 2*w*z*Re[s] + Re[s]^2)^2) >> >> Perhaps that better suits your purposes (although to my eye it's a lot harder to read than my original version that replaces s by x + I y). >> >> >> On Jan 3, 2013, at 9:17 AM, Murray Eisenberg <murray@math.umass.edu> wrote: >> >>> Since there seems to be some typo or else some spurious control code ("=882") in the numerator of your fraction, for purposes of explanation I'll change the numerator just to w. >>> >>> In general, the way to extract the real and imaginary parts of a complex number is to use ComplexExpand along with, of course, Re and Im. Here, though, you have both real and complex variables, so I think you'll need to express the complex s in the form x + I y. Then applying ComplexExpand will treat all the variables w, z, x, and y as real: >>> >>> ComplexExpand[Re[(w)/(s^2 + 2*z*w*s + w^2) /. s > x + I y]] >>> w^3/((w^2 + x^2  y^2 + 2*w*x*z)^2 + (2*x*y + 2*w*y*z)^2) + >>> (w*x^2)/((w^2 + x^2  y^2 + 2*w*x*z)^2 + (2*x*y + 2*w*y*z)^2)  >>> (w*y^2)/((w^2 + x^2  y^2 + 2*w*x*z)^2 + (2*x*y + 2*w*y*z)^2) + >>> (2*w^2*x*z)/((w^2 + x^2  y^2 + 2*w*x*z)^2 + (2*x*y + 2*w*y*z)^2) >>> >>> And similarly for Im. >>> >>> (I've shown the results in onedimensional InputForm for purposes of this plaintext email.) >>> >>> >>> On Jan 2, 2013, at 9:16 PM, Eduardo M. A. M. Mendes <emammendes@gmail.com> wrote: >>> >>>> Hello >>>> >>>> I need to extract the real and imaginary part of the following expression >>>> >>>> (w=882)/(s^2+2*z*w*s+w^2) >>>> >>>> where w and z are positive constants. s is a complex variable. >>>> >>>> Applying Re and Im to the expression does not do much. By hand, one can easily find them. >>>> >>>> What am I missing? >> >>  >> Murray Eisenberg murrayeisenberg@gmail.com >> 80 Fearing Street phone 413 5491020 (H) >> Amherst, MA 010021912 >> >> >> >> >> > >  > Murray Eisenberg murrayeisenberg@gmail.com > 80 Fearing Street phone 413 5491020 (H) > Amherst, MA 010021912 > > > > >

