Question: Subsitution in matrix and computing eigenvalues


Hello everyone, I am working on a Maple code where I am dealing with a matrix X and performing several operations, so I can subsitute a set of lists. However, I feel Im doing some redundant things and I wonder if there are ways to make it more concise and efficient. More specifically,

  1. 'vals' and 'ecs' :
    'vals' gives me a set of lists with the values I'll use in matrix X , e.g., vals := {[-1, 1, 0], [0, -1, -1], [0, -1, 1]}.
    'ecs' creates a set of lists of equations that I can use in 'eval' (or 'subs') function, e.g., ecs := {[[X3_4 = -1, X3_3 = 1, X2_3 = 0]], [[X3_4 = 0, X3_3 = -1, X2_3 = -1]], [[X3_4 = 0, X3_3 = -1, X2_3 = 1]]}.
    But clearly, I'm getting an extra pair of brackets for each list so I will need to use double index in the eval command. Is there a way to avoid this?
  2. In the subsitution step, I've tried with both 'eval' and 'subs' and many modifications to avoid what I did in step 1 but without success. Also I need this extra 'Nelem' to get a list of indices so I can substitute all possible lists of values in 'ecs'.
  3. Finally, I'm wondering if what I'm getting from 'BoolEigs' is actually what I want. My final goal is to check if the eigenvalues of all possible solution matrices I got in 'Xs'  are nonnegative. So I need to avoid numerical computations and perform this step exactly. Is my code correct for this?
     
X := Matrix([[1, -X3_3/2 - 1/2, 0, -X2_3], [-X3_3/2 - 1/2, -2*X3_4 - 1, X2_3, 0], [0, X2_3, X3_3, X3_4], [-X2_3, 0, X3_4, 1]]);
vars := [X3_4, X3_3, X2_3];

w := A^3 - A;
rootz := RootOf(w, A);
Pols := [(-A^2 + 1)/(3*A^2 - 1), (-A^2 - 1)/(3*A^2 - 1), A*(3*A^2 - 1)*1/(3*A^2 - 1)];

vals := {allvalues(eval(Pols, A = rootz))};
ecs := map(x -> convert(vars = x, listofequations), vals);

Nelem := [seq(k, k = 1 .. numelems(vals))];
Xs := map(x -> eval(X, ecs[x][1]), Nelem);#double index for eval
Xz := map(x -> subs(ecs[x][1], X), Nelem);#same for subs

with(LinearAlgebra);
Eigs := map(x -> Eigenvalues(x), Xs);
BoolEigs := map(x -> map(y -> is(Im(y) = 0) and is(0 <= Re(evalf(y))), x), Eigs);
evalf(Eigs);
Please Wait...