6
$\begingroup$

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 ω ]

$\endgroup$
  • 2
    $\begingroup$ You could apply ComplexExpand to the last output again, e.g. ComplexExpand[Im[%]] instead of Im[%] $\endgroup$ – Heike May 1 '12 at 22:58
  • $\begingroup$ 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? $\endgroup$ – Gary Palmer May 2 '12 at 14:02
  • $\begingroup$ @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. $\endgroup$ – Gary Palmer Jul 28 '12 at 14:49
11
$\begingroup$

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 ω]
$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – J. M. will be back soon May 2 '12 at 2:46
  • $\begingroup$ Note that, in place of the assumption like A ∈ Reals you can use the assumption _Symbol ∈ Reals to assume that all explicit variables are real. This allows you to encapsulate this in a function without having to manually pass a list of arguments. For an exhaustive discussion, see here. $\endgroup$ – Jess Riedel Sep 27 '17 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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