0
$\begingroup$

Consider the following code:

ANCL={{0, 25, 0, 0}, {-((36 k1)/41), -((36 k2)/41), 544/5125, -24.0179}, {(900 k1)/41, 11.6625 k2, -(544/205), -24.5524}, {11.6625 k1, 11.6625 k2, 0.0764667, -2.42273}}
Table[Eigenvalues[ANCL], {{k1, {0.001, 0.01, 0.1}}, {k2, {0.01, 0.1, 1}}}];
p = ListPlot[{Re[#], Im[#]} & /@ %, AxesOrigin -> {0, 0}, 
PlotRange -> {{-5, 0}, {-25, 25}}, ImagePadding -> 40, 
AspectRatio -> 1, Frame -> True, 
FrameLabel -> {{Im, None}, {Re, "complex plane"}}, 
PlotStyle -> Directive[Red, PointSize[.02]]];
Show[p]

I get the error "Tag List in {k1,{0.001,0.01,0.1}} is Protected.".

Now I use Quit[] before starting the evaluation. Also, I am really not defining any functions here. The intention is just to evaluate eigenvalues for varying $k_1$ and $k_2$. I checked the other similar questions but I think I do not have the same issue.

P.S. I edited the code to include ANCL.

$\endgroup$
  • $\begingroup$ ANCL is not defined so we can't check that a problem doesn't arise there however it does look like your Table syntax is off a little. You don't need to embrace both the k1 and k2 lists in another List. Check the docs for Table. $\endgroup$ – Quantum_Oli Sep 26 '16 at 6:04
  • $\begingroup$ You should see k1 and k2 change from blue to turquoise in doing so (in the more recent versions of MMA) $\endgroup$ – Quantum_Oli Sep 26 '16 at 6:06
  • 1
    $\begingroup$ Possible duplicate of Good clearing practices $\endgroup$ – JungHwan Min Sep 26 '16 at 6:18
  • $\begingroup$ Try ClearAll and run your definition of ANCL and your code again. $\endgroup$ – JungHwan Min Sep 26 '16 at 6:19
  • $\begingroup$ @JHM I think I already mentioned that I have seen the ClearAll posts...It does not work. Thank you anyways :) $\endgroup$ – Zero Sep 26 '16 at 7:43
3
$\begingroup$

There are two problems with the code in question.

  • Multiple variables in Table need to be enclosed in separate lists i.e: not Table[expr,{{var1,specs},{var2specs}}] but rather Table[expr,{var1,specs},{var2,specs}]. This is the source of the protected tag error.
  • ListPlot needs a list of coordinates {{x1,y1},{x2,y2},...} rather than the matrix provided as an output of Table in order to plot correctly.

With those elements in mind, let me provide you with an alternative visualisation for your problems, using Manipulate:

ANCL[k1_,k2_] := {{0, 25, 0, 0}, {-((36 k1)/41), -((36 k2)/41), 
   544/5125, -24.0179}, {(900 k1)/41,11.6625 k2, -(544/205), -24.5524},
   {11.6625 k1, 11.6625 k2,0.0764667, -2.42273}}

I write the matrix as a function of $k1$ and $k2$ for convenience (don't forget to clear the previous definition of ANCL).

Manipulate[
 ListPlot[
  Transpose[{Re@Eigenvalues[ANCL[k1, k2]], 
    Im@Eigenvalues[ANCL[k1, k2]]}], 
  PlotStyle -> Directive[Red, PointSize[0.02]], Frame -> True, 
  FrameLabel -> {{Im, None}, {Re, "complex plane"}}]
 , {k1, {0.001, 0.01, 0.1}}, {k2, {0.01, 0.1, 1}}]

Or maybe you wanted all the eigenvalues on the same plot, in which case:

ListPlot[Flatten[
  Table[Transpose[{Re@Eigenvalues[ANCL[k1, k2]], 
     Im@Eigenvalues[ANCL[k1, k2]]}], {k1, {0.001, 0.01, 
     0.1}}, {k2, {0.01, 0.1, 1}}], 2], 
 PlotStyle -> Directive[Red, PointSize[0.02]], Frame -> True, 
 FrameLabel -> {{Im, None}, {Re, "complex plane"}}]

Be mindful of the level specification ($2$) in the argument of Flatten.

Edit: With differenciated eigenvalues and tooltips!

ListPlot[MapThread[
  Tooltip, {Flatten[
    Table[Transpose[{Re@Eigenvalues[ANCL[k1, k2]], 
       Im@Eigenvalues[ANCL[k1, k2]]}], {k1, {0.001, 0.01, 
       0.1}}, {k2, {0.01, 0.1, 1}}], 1], 
   Map[ToString, 
    Flatten[Table[{k1, 
       k2}, {k1, {0.001, 0.01, 0.1}}, {k2, {0.01, 0.1, 1}}], 1]]}], 
 PlotStyle -> Directive[PointSize[0.02]], Frame -> True, 
 FrameLabel -> {{Im, None}, {Re, "complex plane"}}, 
 PlotLegends -> 
  SwatchLegend[
   Map[ToString, 
    Flatten[Table[{k1, 
       k2}, {k1, {0.001, 0.01, 0.1}}, {k2, {0.01, 0.1, 1}}], 1]], 
   LegendLabel -> Text["{k1,k2}"]]]

$\endgroup$
  • $\begingroup$ Great but can you add how to make them different color. I can imagine it won't be easy with two variables. But if lets say I chose to fix and vary other over a range, then how can I have a colorbar that represents it. I know the commands but getting the syntax wrong always frustrates me $\endgroup$ – Zero Sep 26 '16 at 19:29
  • $\begingroup$ Seeing the Directive[Red] in your code I thought you wanted all the datapoints to be red. If you take off the Red in the Directive and Flatten at level 1 instead you will get each set of 4 eigenvalues coloured differently. $\endgroup$ – Musang Sep 27 '16 at 10:16
  • $\begingroup$ I've added legends and tooltips. I hope this motivates you to get a sense of the formatting syntax. $\endgroup$ – Musang Sep 27 '16 at 10:22

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