0
$\begingroup$

This question already has an answer here:

I define

ψ1 = Sqrt[Subscript[ρ, 1][t]] E^(I Subscript[θ, 1][t]);
ψ2 = Sqrt[Subscript[ρ, 2][t]] E^(I Subscript[θ, 2][t]);

and

eq1 = (I ℏ D[ψ1, t] - U ψ1 - K ψ2)/E^(I Subscript[θ, 1][t]) // FullSimplify

gives

enter image description here

I want to get the imaginary part of the above expression where $\rho$ is positive, and $\theta$ is real.

The result should be

enter image description here

while ComplexExpand gives

enter image description here

How do I do it correctly?

$\endgroup$

marked as duplicate by Lukas Lang, Sektor, halirutan, MarcoB, m_goldberg May 30 '18 at 14:20

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ If you simplify assuming Subscript[ρ, 1][t] > 0 and Subscript[ρ, 2][t] > 0, it works as expected $\endgroup$ – Lukas Lang May 30 '18 at 7:23
  • 2
    $\begingroup$ FYI, You should avoid using Subscript while defining symbols (variables). Subscript[x, 1] is not a symbol, but a composite expression where Subscript is an operator without built-in meaning. You expect to do $x_1=2$ but you are actually doing Set[Subscript[x, 1], 2] which is to assign a Downvalue to the operator Subscript and not an Ownvalue to an indexed x as you may intend. $\endgroup$ – rhermans May 30 '18 at 8:16
2
$\begingroup$

Try the following.

Here are your expressions:

ψ1 = 
  Sqrt[Subscript[ρ, 1][t]] E^(I Subscript[θ, 1][t]);
ψ2 = 
  Sqrt[Subscript[ρ, 2][t]] E^(I Subscript[θ, 2][t]);
eq1 = 
  (I*ℏ D[ψ1, t] - U ψ1 - k ψ2)/E^(I Subscript[θ, 1][t]) // FullSimplify

enter image description here

I assume, your K is not the reserved Mma constant and replaced it, therefore, by the small k above.

Let us now represent the exponent in the trigonometric form and replace the imaginary unit by any letter, say, by X for further use:

eq2 = ExpToTrig[eq1];
eq3=eq2 /. Complex[0, a_] -> X*a

enter image description here

Now this:

Coefficient[eq3, X]

makes the job:

enter image description here

Have fun!

$\endgroup$
  • $\begingroup$ Great, I actually tried i->x before, however, it can not replace the i/2. Clever trick for Complex[0, a_] -> X*a $\endgroup$ – matheorem May 31 '18 at 0:23

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