4
$\begingroup$

Consider the example below:

Z0 = {{1, 0, 0}, {0, 1, -2}, {3, 0, 1}};
Z1 = {{1, 2, 0}, {1, 0, 3}, {0, 0, 0}};
Z2 = {{0, 0, 0}, {-2, 0, 1}, {0, -3, 1}};

Plot[
 Sort@(Re /@ Eigenvalues[Z0 + u Z1 + u^2 Z2]),
 {u, -2, 2},
 PlotRange -> All,
 (*ColorFunction ->,*)
 AspectRatio -> 1
 ]

which produces the following output:

enter image description here

Basically, I am plotting the real part of the eigenvalues of the matrix $Z(u) = Z_0 + u Z_1 + u^2 Z_2$ as a function of the parameter $u \in [-2,+2]$. The use of Sort ensures that the curves are "joined correctly", avoiding the following undesired effect (at $u=1$ in this example):

enter image description here

Is it possible to develop a ColorFunction for this plot, so that the color of each point is a function of the respective imaginary part of the eigenvalue (which will allow to identify which curve represents each mode)?

$\endgroup$

1 Answer 1

5
$\begingroup$

Here's a first pass at an answer. It's not perfect, because it's hard to control the color scheme numerically. It could be improved easily, I think, but we'd require more information about what you'd need. In any case...

Z0 = {{1, 0, 0}, {0, 1, -2}, {3, 0, 1}};
Z1 = {{1, 2, 0}, {1, 0, 3}, {0, 0, 0}};
Z2 = {{0, 0, 0}, {-2, 0, 1}, {0, -3, 1}};
f[u_] = Eigenvalues[Z0 + u Z1 + u^2 Z2];

We first define a function which does the Sorting for us on the fly. This allows us to plot the different branches separately:

g[k_Integer /; 1 <= k <= 3][u_] := SortBy[f[u], {N@*Re, N@*Im}][[k]]

Then, we use plot the real part of this and use the imaginary part as the input to a ColorFunction:

Show@Table[Plot[Re@g[k][u], {u, -2, 2},
   PlotRange -> All,
   ColorFunction -> Function[{x, y}, Hue@Im@g[k][x]],
   ColorFunctionScaling -> False,
   AspectRatio -> 1
  ], {k, 1, 3}]

enter image description here

$\endgroup$
2
  • $\begingroup$ Thank you so much. That was exctly what I needed. Just a short correction: the ColorFunction in this case should be: ColorFunction -> Function[{x, y}, Hue@Im@g[k][x]] instead of ColorFunction -> Function[{x, y}, Hue@Im@g[1][x]] $\endgroup$ Commented Mar 23, 2017 at 1:40
  • $\begingroup$ @RenatoOrsino. Fixed! $\endgroup$
    – march
    Commented Mar 23, 2017 at 1:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.