# How do I solve for the real and complex parts of an equation simultaneously?

If I were to have an equation, say something similar to...

(1-Sqrt[x - I y])/(1+Sqrt[x - I y]) = A + I B


Where I = Sqrt[-1], is there a way for Mathematica to give me A = ... and B = ..., i.e. both real and imaginary parts of the equation simultaneously?

• Hi ! You are not using the correct syntax - are you sure you know your way around Mathematica ? Jul 28, 2014 at 8:23
• Hi, I'm actually brand new to Mathematica. That equation is just an example I was using to describe my problem, not the one I need to solve (the real one is fairly long). Is there a better way I should be asking my question?
– Tait
Jul 28, 2014 at 8:34
• In that case - I don't think there is :) You can start by looking at Reduce, Solve and ComplexExpand. Jul 28, 2014 at 8:51
• Ok great, thank you! So for example, if I wanted to use the ComplexExpand command on the above expression, it would look something like this... ComplexExpand[(1-Sqrt[x - I y])/(1+Sqrt[x - I y]) = A + Ib,{A}] for the real part?
– Tait
Jul 28, 2014 at 9:41
• Also, thank you Sjoerd for editing it to the correct format
– Tait
Jul 28, 2014 at 9:43

Something like this:

ComplexExpand[
Solve[
{
Re[(1 - Sqrt[x - I y])/(1 + Sqrt[x - I y])] == A,
Im[(1 - Sqrt[x - I y])/(1 + Sqrt[x - I y])] == B
},
{A, B}
],
TargetFunctions -> {Re, Im}
]

(* {{A -> 1/((1 + (x^2 + y^2)^(1/4)*Cos[(1/2)*ArcTan[x, -y]])^2 +
Sqrt[x^2 + y^2]*Sin[(1/2)*ArcTan[x, -y]]^2) -
(Sqrt[x^2 + y^2]*Cos[(1/2)*ArcTan[x, -y]]^2)/
((1 + (x^2 + y^2)^(1/4)*Cos[(1/2)*ArcTan[x, -y]])^2 +
Sqrt[x^2 + y^2]*Sin[(1/2)*ArcTan[x, -y]]^2) -
(Sqrt[x^2 + y^2]*Sin[(1/2)*ArcTan[x, -y]]^2)/
((1 + (x^2 + y^2)^(1/4)*Cos[(1/2)*ArcTan[x, -y]])^2 +
Sqrt[x^2 + y^2]*Sin[(1/2)*ArcTan[x, -y]]^2),
B -> -((2*(x^2 + y^2)^(1/4)*Sin[(1/2)*ArcTan[x, -y]])/
((1 + (x^2 + y^2)^(1/4)*Cos[(1/2)*ArcTan[x, -y]])^2 +
Sqrt[x^2 + y^2]*Sin[(1/2)*ArcTan[x, -y]]^2))}} *)

• Wow thank you so much! So just so I'm clear, by doing this, it is solving the equation one time only for the real part, A, and then solving it again for the imaginary part, B?
– Tait
Jul 28, 2014 at 13:30
• @tair something like that, but don't forget that the real and imaginary parts may be totally different and are completely independent, so saying that you use the same equation twice is not completely true. Jul 31, 2014 at 15:57