# Finding imaginary part of an expression [closed]

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


 n+c/((f+b)+Sqrt[uy-gh])

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

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.

Update: This works as expected:

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

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


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

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

In:= Simplify[Im[exp], Element[Variables[exp], Reals]]
Out= 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:= exp = I n + (a + d + I c)/((f + b) + Sqrt[u y + g h]);

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

In:= Simplify[Im[exp], And @@ (# > 0 & /@ Variables[exp])]
Out= n + c/(b + f + Sqrt[g h + u y])