# Solving algebraic equations

How may I make n and k in terms of x and y in this equation?:

$$\frac{1-n-i k}{1+n+i k}=\sqrt{x} e^{i y}$$

I have tried separating the real and imaginary terms on the left hand side using complex expand so that I can have 2 sets of equations now but I have no idea how to continue?

ComplexExpand[((1 - n - I k)/(1 + n + I k))]

-

by hand:

\begin{align*} \frac{1-n-ik}{1+n+ik} & =\sqrt{x}e^{iy}\\ \frac{\left( 1-n-ik\right) \left( 1+n-ik\right) }{\left( 1+n+ik\right) \left( 1+n-ik\right) } & =\sqrt{x}\left( \cos y+i\sin y\right) \\ \frac{-k^{2}-2ik-n^{2}+1}{k^{2}+n^{2}+2n+1} & =\sqrt{x}\cos y+i\sqrt{x}\sin y\\ i\left( \frac{-2k}{k^{2}+n^{2}+2n+1}\right) +\frac{-k^{2}-n^{2}+1} {k^{2}+n^{2}+2n+1} & =\sqrt{x}\cos y+i\sqrt{x}\sin y \end{align*} Hence \begin{align*} \sqrt{x}\cos y & =\frac{-k^{2}-n^{2}+1}{k^{2}+n^{2}+2n+1}\\ \sqrt{x}\sin y & =\frac{-2k}{k^{2}+n^{2}+2n+1}% \end{align*}

Use Mathematica to help solve the last part

Clear[x, y, n, k]
lhs = (1 - n - I k)/(1 + n + I k);
rhs = Sqrt[x] Exp[I y];
lhsReal = ComplexExpand[Re[lhs]];
lhsIm = ComplexExpand[Im[lhs]];
rhsReal = ComplexExpand[Re[rhs]];
rhsIm = ComplexExpand[Im[rhs]];
eq1 = Assuming[Element[{x, y}, Reals] && x > 0 && y > 0, Simplify[lhsReal == rhsReal]];
eq2 = Assuming[Element[{x, y}, Reals] && x > 0 && y > 0, Simplify[lhsIm == rhsIm]];


sol=Solve[{eq1, eq2}, {n, k}]


Update:

let me simplify the solution so verify it is the same solution obtained by the nice method below by b.gatessucks by applying Simplify :

 Simplify[k /. sol]


 Simplify[n /. sol]


-

This might be what you want.

With[{ee = ((1 - n - I k)/(1 + n + I k))},
Solve[ComplexExpand[{Re[x*Exp[I*y] - ee], Im[x*Exp[I*y] - ee]},
TargetFunctions -> {Re, Im}] == 0, {k, n}]]

Out[376]= {{k -> -((2 x Sin[y])/(
1 + 2 x Cos[y] + x^2 Cos[y]^2 + x^2 Sin[y]^2)),
n -> (1 - x^2 Cos[y]^2 - x^2 Sin[y]^2)/(
1 + 2 x Cos[y] + x^2 Cos[y]^2 + x^2 Sin[y]^2)}}

-

I'd set z = n + I k, solve for z and then use ComplexExpand to read off real and imaginary parts (n and k respectively) :

z /. First@Solve[(1 - z)/(1 + z) == Sqrt[x] Exp[I y], z]
(* (1 - E^(I y) Sqrt[x])/(1 + E^(I y) Sqrt[x]) *)

sol=ComplexExpand[(1 - E^(I y) Sqrt[x])/(1 +  E^(I y) Sqrt[x]), TargetFunctions -> {Re, Im}] ;

(* n *)
Simplify[sol /. I -> 0, Assumptions -> {x > 0}]
(* (1 - x)/(1 + x + 2 Sqrt[x] Cos[y]) *)

(* I k *)
Simplify[sol - (sol /. I -> 0), Assumptions -> {x > 0}]
(* -((2 I Sqrt[x] Sin[y])/(1 + x + 2 Sqrt[x] Cos[y])) *)

-