4
$\begingroup$

This is a sort of continuation of How can I make a list of values "remember" the entered parameters?

I have some cubic function which solves for a variable r for different values of a parameter d:

s[d_?NumericQ] := 
 SolveValues[r^3 - 10 r^2 + (25 + 100*d^{2}) r - 4 == 0, r]
rvalues = 
 Join @@ (Transpose /@ 
    Table[{Array[d &, Length[s[d]]], s[d]}, {d, 0, 0.02, 0.001}])

and generates the following list in the form {d,r}

enter image description here

Now I input this list into another function that solves for some eigenvalues where where #[[1]] is the d and #[[2]] is the r:

(0.5 - 0.2 #[[2]] + 
    PlusMinus[Sqrt[0.01 #[[2]]^2 - #[[1]]^2]]) & /@ rvalues

which generates

enter image description here

I would like to create a scatter plot for this list where the x-variable is d, and the y-variable is the magnitude of the eigenvalues.

I can imagine something like

LambdaRe = ListPlot[{{d_1,lambda_1},...,{d_i,lambda_i}} ];
LambdaIm = ListPlot[{...},PlotStyle->Red];

Show[LambdaRe,LambdaIm]

It is important to note that I want to plot each complex eigenvalue as two separate values, ignoring the imaginary part i and simply plotting each magnitude in a different color or otherwise.

$\endgroup$

1 Answer 1

5
$\begingroup$
s[d_?NumericQ] := SolveValues[r^3 - 10 r^2 + (25 + 100*d^{2}) r - 4 == 0, r]
eigenfunc[{d_, r_}] := {d, (0.5 - 0.2 r + # Sqrt[0.01 r^2 - d^2])} & /@ {1, -1};

rvalues = Join @@ (Transpose /@ 
  Table[{Array[d &, Length[s[d]]], s[d]}, {d, 0, 0.2, 0.01}]);

eigenvalues = Catenate[eigenfunc /@ rvalues];

ListPlot[{
  MapAt[Re, eigenvalues, {All, 2}], 
  MapAt[Im, eigenvalues, {All, 2}]
 }, PlotStyle -> {Blue, Red}, PlotLegends -> {Re, Im}]

enter image description here

$\endgroup$
4
  • $\begingroup$ Where do the vertical bars come from? $\endgroup$
    – ξύλο
    Commented Dec 29, 2022 at 20:54
  • $\begingroup$ They come from Around (your PlusMinus). $\endgroup$
    – Domen
    Commented Dec 29, 2022 at 21:05
  • $\begingroup$ The PlusMinus comes from the quadratic formula (used to find the eigenvalues). I didn't mean for it to be the error of the calculation. Is there a way to plot it as such (two values rather than a central value with bars)? $\endgroup$
    – ξύλο
    Commented Dec 29, 2022 at 21:16
  • 2
    $\begingroup$ Oh, okay, I have fixed it. $\endgroup$
    – Domen
    Commented Dec 29, 2022 at 21:45

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.