# How to plot the absolute values of the solutions to a parametric equation versus the parameter?

Mathematical formulation of my problem: Let $$\Theta\subset\Bbb R$$ be an interval. For each $$\theta\in\Theta$$ let $$f_\theta: \Bbb C\to\Bbb C$$ be some function and $$z_{\theta,1},\ldots,z_{\theta,n(\theta)}$$ the (finitely many) solutions to $$f_\theta(z)=0$$. I would like to plot the multifunction

$$\Theta\ni\theta\mapsto \left(|z_{\theta,1}|,\ldots,|z_{\theta,n(\theta)}|\right)\in\bigcup_{n\in\Bbb N}\Bbb R^n$$

in a plot with two axes, one for $$\theta$$ and one in which all values $$|z_{\theta,1}|,\ldots,|z_{\theta,n(\theta)}|$$ are plotted.

The specific function I am interested in is essentially

$$f_\theta(z)=(1+i\theta)z-(1+i)|z|^2z+0.01,$$

so $$n(\theta)\le3$$. The solutions $$z_{\theta,1},\ldots,z_{\theta,n(\theta)}$$ need not be exact, numerical approximations will do just fine.

What I've done so far: Writing $$z=z_1+iz_2$$ and using

{{z11, z12}, {z21, z22}, {z31, z32}} =
{z1, z2} /.
NSolve[
z1 - theta z2 - (z1^2 + z2^2) z1 + (z1^2 + z2^2) z2 + 0.01 == 0 &&
theta z1 + z2 - (z1^2 + z2^2) z1 - (z1^2 + z2^2) z2 == 0,
{z1, z2}
]


I get solutions -- plus perhaps some nonsensical solution with "complex real part". So what I could try next is to "forget" these nonsensical solutions and then define a function depending on $$\theta$$ which I could plot, but I'm kind of lost there since I'm quite new to Mathematica. Any help is very much appreciated.

I think you can use ComplexExpand to construct the appropriate equations for the real and imaginary parts, and then use the domain Reals to make sure that the real and imaginary parts are real numbers. Your function:

f[θ_] := (1 + I θ) z - (1 + I) Abs[z]^2 z + 1/100


Then, use ComplexExpand to convert to coupled equations for the real and imaginary parts:

Thread[
Block[{z = a + I b}, ComplexExpand[ReIm @ f[θ]]] == 0
]


{1/100 + a - a^3 + a^2 b - a b^2 + b^3 - b θ == 0, -a^3 + b - a^2 b - a b^2 - b^3 + a θ == 0}

Finally, a function to solve the equations:

roots[θ_] := With[{eqns = Block[{z = a + I b}, ComplexExpand[ReIm @ f[θ]]]},
Flatten[{a + b I} /. NSolve[Thread[eqns == 0], {a, b}, Reals]]
]


Example:

roots


{0.709594 - 0.709594 I, -0.704593 + 0.704593 I, -0.00500025 + 0.00500025 I}

Check:

f /. z->roots


{-2.08722*10^-14 + 0. I, 2.88658*10^-15 + 0. I, 2.08619*10^-17 + 0. I}

which is zero up to machine number fuzziness.

• Thanks a lot for your nice help! Since roots is a multi-valued function where the number of values depends on $\theta$, I still have trouble plotting it. How is it done? – Mars Plastic Oct 25 '19 at 17:15