0
$\begingroup$

How can I find the Imaginary part of an expression by knowing that all parameters are real?

exp= I n + (a+d+I c)/((f+b)+Sqrt[uy-gh])

The answer should be

 n+c/((f+b)+Sqrt[uy-gh])
$\endgroup$
  • $\begingroup$ Have you tried Im[expr]? $\endgroup$ – TheYeda Apr 20 '17 at 6:22
  • $\begingroup$ Yes, it returns lots of complicated arguments. I need to use the information that all parameters are real to make the anwer better@YashGandhi $\endgroup$ – Sonia Sohi Apr 20 '17 at 6:29
  • $\begingroup$ Can you add some more information here? This doesn't really help. May be an example? $\endgroup$ – TheYeda Apr 20 '17 at 6:33
  • $\begingroup$ I added it @YashGandhi $\endgroup$ – Sonia Sohi Apr 20 '17 at 6:39
  • 3
    $\begingroup$ Well at least you need to type the imaginary unit correctly, it should be I n or I*n instead of in $\endgroup$ – vapor Apr 20 '17 at 7:18
2
$\begingroup$

This works:

ComplexExpand@Im[exp /. Sqrt[-gh + uy] -> X] /. X -> Sqrt[-gh + uy]

ComplexExpand assumes all unknown symbols are real. Hence by replacing the square root by an a single variable you get your desired result (which is only correct if the square root is real!). Alternatively, you could do

Simplify[ComplexExpand@Im@exp, uy>gh]

but that produces a more messy (but correct) result.

| improve this answer | |
$\endgroup$
0
$\begingroup$

Update: This works as expected:

In[610]:= exp = I n + (a + d + I c)/((f + b) + Sqrt[u y - g h]);

In[635]:= Simplify[Im[exp], Element[Variables[exp], Reals] && (b + f != -Sqrt[u y - g h]) && (u y >= g h)]
Out[635]= n + c/(b + f + Sqrt[-g h + u y])

Original: Assuming all your variables are reals, Here is what you get:

In[610]:= exp = I n + (a + d + I c)/((f + b) + Sqrt[u y - g h]);

In[611]:= Simplify[Im[exp], Element[Variables[exp], Reals]] 
Out[611]= n + Im[(a + I c + d)/(b + f + Sqrt[-g h + u y])]

The problem here is with the signs of u,v,g,h. As Mathematica doesn't know what they are, it gives you a result in Mathematica expressions. However, if you just change the sign of the expression in square root, you get an expected result:

In[607]:= exp = I n + (a + d + I c)/((f + b) + Sqrt[u y + g h]);

In[608]:= Simplify[Im[exp], Element[Variables[exp], Reals]] 
Out[608]= n + Im[(a + I c + d)/(b + f + Sqrt[g h + u y])]

In[609]:= Simplify[Im[exp], And @@ (# > 0 & /@ Variables[exp])]
Out[609]= n + c/(b + f + Sqrt[g h + u y])
| improve this answer | |
$\endgroup$

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