Solve
works, but first let's clean up the definition to avoid unnecessary singularities:
f[x_, y_] := (-I*x + 2*y^2)^2 + x^2 - 4*y^4*Sqrt[1 - I*x/(y^2)];
f[x, y] // TraditionalForm
$ x^2+\left(2 y^2-i x\right)^2-4 y^4 \sqrt{1-\frac{i x}{y^2}}$
This is easily simplified by inspection, but we can get Mathematica to help us. I cheat a little by giving it some overly strong assumptions; the purpose is to get it to "recognize" that the $1/y^2$ term is a removable singularity:
Assuming[y > 0, FullSimplify[f[x, y]]] // TraditionalForm
$4 y^2 \left(y \left(y-\sqrt{y^2-i x}\right)-i x\right)$
OK, that looks good, so let's memorialize it:
g[x_, y_] := Evaluate[Assuming[y > 0, FullSimplify[f[x, y]]]]
Now we invoke Solve
:
Solve[g[x, y] == 0, {y}]
$\left\{\{y\to 0\},\left\{y\to -\sqrt[4]{-1} \sqrt{x}\right\},\left\{y\to \sqrt[4]{-1} \sqrt{x}\right\}\right\}$
(It is wise to pause here to reflect on the nature of these solutions due to ambiguities in the square and fourth roots: there are two square roots and four fourth roots involved in each solution, potentially designating $16$ different functions in all. However, it is evident that if we allow $x$ to be negative and permit complex square roots to be computed, then we need consider only the primitive fourth root $\exp{i \pi / 4}$ and its negative, both of which show up in the last pair of solutions. We conclude that we should retain all the solutions Solve
has provided and allow $x$ to range over all real values, positive and negative.)
Let's encapsulate these solutions within yet another function. This re-solves the equations and extracts the solutions as expressions:
h[x_] := Evaluate@(Flatten[Solve[g[x, y] == 0, {y}]] /. Rule[y, f_] :> f)
h[x] // TraditionalForm
$\left\{0,-\sqrt[4]{-1} \sqrt{x},\sqrt[4]{-1} \sqrt{x}\right\}$
To plot a complex function of a real argument $x$, $y(x)$, we can employ three dimensions: its graph will be a curve. Because there are three separate solutions, we get parts of three such curves using ParametricPlot3D
. Its three components are the parameter $x$ and the real and imaginary parts of $y(x)$. I give a fully general expression by selecting random colors for the curves: this avoids even having to count the number of distinct solutions in advance. So that the complex part is appropriately rendered, I use the BoxRatios
argument to specify that the last two dimensions (real and imaginary axes) have the same scales.
ParametricPlot3D[Evaluate[{x, Re[#], Im[#]} & /@ h[x]], {x, -2, 2},
PlotStyle -> Table[{Thick, Hue[RandomReal[], .8, .8]}, {i, h[0]}],
BoxRatios -> {Automatic, 1, 1}, Boxed -> False,
AxesLabel -> {x, Re[y], Im[y]}]
You can also use ParametricPlot
to render the image of $y$ in the complex plane, perhaps distinguishing the values of $x$ by color. Just drop the first parameter, leaving the real and imaginary parts to be drawn:
ParametricPlot[Evaluate[{Re[#], Im[#]} & /@ h[x]], {x, -2, 2},
PlotStyle -> Thickness[0.02],
ColorFunction -> Function[{t, x, y}, Hue[t]],
AxesLabel -> {Re[y], Im[y]}, LabelStyle -> Medium]
FindRoot
. $\endgroup$