Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Does the Im function work with symbolic arguments?

Clear[ y, t, k, ω ]

A ( Cos[ k y ] + I Sin[ k y ] ) 2I Sin[ ω t ] //ComplexExpand

(* Output: 2 I A Cos[ k y] Sin[ t ω ] - 2 A Sin[ k y ] Sin[ t ω ] *)

Im[ % ]

(* Output: -2 Im[ A Sin[ k y ] Sin[ t ω ] ] + 2 Re[ A Cos[ k y ] Sin[ t ω ] ] *)

Expected output: -2 A Sin[ k y ] Sin[ t ω ]

share|improve this question
2  
You could apply ComplexExpand to the last output again, e.g. ComplexExpand[Im[%]] instead of Im[%] –  Heike May 1 '12 at 22:58
    
I'm amazed by all the good answers, but still a little puzzled. One says that ComplexExpand is not needed, the other that TargetFunctions is not needed. Both lead to succinct expressions that give the correct answer. What is it that makes one or the other, or neither, preferable? –  Gary Palmer May 2 '12 at 14:02
    
@Artes, Sorry for not responding. I'm not very good at forum protocols, as I don't use them very often, each is a little different, and I find the locations of the buttons a little confusing. I think I forgot to set automatic email for this one. Even now, I am not sure that I have satisfied the request. I'm happy with the answers. –  Gary Palmer Jul 28 '12 at 14:49

1 Answer 1

up vote 9 down vote accepted

You should assume that your variables are real, (if you want M to proceed further) because Mathematica treats variables in general as complex. One of many ways to do it :

 expr = A ((Cos[k y] + I Sin[k y]) 2 I Sin[t ω]); 
 Refine[ Im[ expr], (A | k y | t ω) ∈ Reals]
2 A Cos[k y] Sin[t ω]

We needn't use ComplexExpand defining expr, but in this case it is the simplest approach (pointed out by Heike) :

ComplexExpand @ Im @ expr

Some other ways of imposing assumptions :

Assuming[(A | k y | t ω) ∈ Reals, Refine[ Im[ expr] ] ]

another way yielding the same result :

Block[{$Assumptions = A ∈ Reals && k y ∈ Reals && t ω ∈ Reals},
       Refine @ Im[ expr] ]
 2 A Cos[k y] Sin[t ω]
share|improve this answer
    
ComplexExpand[] actually works nicely here: ComplexExpand[Im[A ((Cos[k y] + I Sin[k y])*2 I Sin[ω t])], TargetFunctions -> Im]; unfortunately the TargetFunctions option is not as well-known as I think it should be. –  J. M. May 2 '12 at 2:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.