I have a $45\times 45$ matrix $H$ and its elements depend on $Ca$. I want to find its eigenvalues (which will also depend on $Ca$). I do this using:
evals = Simplify[Eigenvalues[H], Element[{Ca}, Reals]];
This gives me all the 45 eigenvalues of $H$. Now, I want see the dependence of these eigenvalues on $Ca$ (by plotting them against $Ca$). This is done using:
data1 = Transpose[{x, evals[[1]] /. Ca -> x}];
I do this for different evals[[i]] and in most of the cases, I get the following error:
Root::npoly: {0. +4. #1-4. #1^2+#1^3,2.4875*10^-11+3.9802 #1-3.99015 #1^2+#1^3,7.92*10^-10+3.96079 #1-3.9806 #1^2+#1^3,5.98388*10^-9+3.94177 #1-3.97135 #1^2+#1^3,2.5088*10^-8+3.92314 #1-3.9624 #1^2+#1^3,<<42>>,0.00438622 +3.43457 #1-3.86135 #1^2+#1^3,0.00484128 +3.43002 #1-3.8656 #1^2+#1^3,0.00533172 +3.42579 #1-3.87015 #1^2+#1^3,<<351>>} is not a polynomial in #1.
First, I thought this may be caused because not all eigenvalues are dependent on $Ca$, so I tired to check this using:
Table[
With[{globalQ = Context@# === "Global`" &}, DeleteDuplicates@Cases[evals[[j]], _Symbol?globalQ, Infinity]],
{j, 1, 45}]
I got this code from here: Extracting variables from an expression. This gives me:
{{Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}, {Ca}}
This means that all eigenvalues are, in fact, dependent on $Ca$.
I want to know what is the cause of this error? I am just substituting the values. Why is Mathematica calculating the roots? Also, how do I make my code work correctly?
I have just started using Mathematica, so its possible I'm interpreting the error totally wrong.
Transpose[{x, evals[[1]] /. Ca -> x}]Why are you transposing? If you want to plot, just do something likePlot[evals[[1]],{Ca,-10,10}]– flinty Jul 19 '20 at 17:47Rootis complaining about looks like a vector of polynomials, not just one polynomial. I thoughtxmight be a vector, but I didn't get the same form when I tried it. – Michael E2 Jul 19 '20 at 17:50xwith a list of values?Rootis not listable, so to builddata1you should map over the different values ofx, i.e.data1 = Transpose[{#, evals[[1]] /. Ca -> #}&/@x]. – Hausdorff Jul 19 '20 at 19:41