1
$\begingroup$

I am new to Mathematica, so I'm not sure about the ins and outs of what's possible and what is not.

I am trying to view the eigenvalues of multiple matrices at once. In particular, this matrix:

$$\begin{pmatrix} a & b & c \\ 1 & 0 & 1 \\ 0 & 1 & 0 \\ \end{pmatrix}$$

for $\{ a,b,c\} \in \{ -1,0,1 \}$


I have been able to do this for a significantly simpler example:

$\begin{pmatrix} a & 1 \\ 1 & 0\end{pmatrix}$

by doing the following:

L = Table[{{{a, 1}, {1, 0}}}, {a, -1, 1, 1}]

H = Eigenvalues /@ L

Of course, I'm not sure if this the best way to do this in this case, and from what I've tried, this doesn't seem to be an easy thing to do to grow this for bigger matrices or more variables.


So back to where I'm stuck - I've tried starting off with:

L = Table[{{a, b, c}, {1, 0, 1}, {0, 1, 0}}, {a, -1, 1, 1}, {b, -1, 1,
1}, {c, -1, 1, 1}]

H = Eigenvalues /@ L

This doesn't work; particularly, it throws up a list of vectors, saying they're at position 1 and is not a non-empty square matrix.

So how would I go about doing this? And is it suitable for being able to easily expand it to bigger matrices / more variables?

Many thanks!

$\endgroup$
  • 1
    $\begingroup$ Try Eigenvalues /@ Flatten[L, 2]. Notice that your Table expression made a nested list of matrices, not a flat one (check Dimensions[L]). You need to flatten it to a list of 27 $3\times 3$ matrices instead. $\endgroup$ – MarcoB Mar 8 at 15:53
  • 1
    $\begingroup$ You can also do (1) H = Map[Eigenvalues, L, {3}]; or (2) H2 = Table[ Eigenvalues@{{a, b, c}, {1, 0, 1}, {0, 1, 0}}, {a, -1, 1, 1}, {b, -1, 1, 1}, {c, -1, 1, 1}] $\endgroup$ – kglr Mar 8 at 16:15
  • $\begingroup$ Thank you both for your answers; both are extremely useful! :) $\endgroup$ – user143137 Mar 8 at 16:48
3
$\begingroup$

Notice that your Table expression made a nested list of matrices, not a flat one (check Dimensions[L]). You need to flatten it to a list of 27 3×3 matrices instead, so you could use Eigenvalues /@ Flatten[L, 2].

However, an alternative method to make your matrices is the following:

Lnew = Join[{#}, {{1, 0, 1}, {0, 1, 0}}] & /@ Tuples[{-1, 0, 1}, {3}];
Dimensions[Lnew]

(* {27, 3, 3} *)

Then Eigenvalues /@ Lnew will work directly

$\endgroup$
2
$\begingroup$
L2 = {#, {1, 0, 1}, {0, 1, 0}} & /@ Tuples[{-1, 0, 1}, {3}]
Dimensions[L2]

{27, 3, 3}

Eigenvalues /@ L2

{{-1, 0, 0}, {Root[-1 + #1^2 + #1^3 &, 3], Root[-1 + #1^2 + #1^3 &, 2], Root[-1 + #1^2 + #1^3 &, 1]}, {-1 + I, -1 - I, 1}, {1/2 (-1 - Sqrt[5]), 1/2 (-1 + Sqrt[5]), 0}, {-1, -1, 1}, {Root[-2 - #1 + #1^2 + #1^3 &, 3], Root[-2 - #1 + #1^2 + #1^3 &, 2], Root[-2 - #1 + #1^2 + #1^3 &, 1]}, {-2, 1, 0}, {Root[-1 - 2 #1 + #1^2 + #1^3 &, 1], Root[-1 - 2 #1 + #1^2 + #1^3 &, 3], Root[-1 - 2 #1 + #1^2 + #1^3 &, 2]}, {-Sqrt[2], Sqrt[ 2], -1}, {-1, (-1)^(1/3), -(-1)^(2/3)}, {0, 0, 0}, {1, -(-1)^(1/3), (-1)^(2/3)}, {Root[1 - #1 + #1^3 &, 1], Root[1 - #1 + #1^3 &, 3], Root[1 - #1 + #1^3 &, 2]}, {-1, 1, 0}, {Root[-1 - #1 + #1^3 &, 1], Root[-1 - #1 + #1^3 &, 3], Root[-1 - #1 + #1^3 &, 2]}, {1/2 (-1 - Sqrt[5]), 1, 1/2 (-1 + Sqrt[5])}, {-Sqrt[2], Sqrt[2], 0}, {1/2 (1 + Sqrt[5]), -1, 1/2 (1 - Sqrt[5])}, {1 + I, 1 - I, -1}, {Root[1 - #1^2 + #1^3 &, 3], Root[1 - #1^2 + #1^3 &, 2], Root[1 - #1^2 + #1^3 &, 1]}, {1, 0, 0}, {Root[2 - #1 - #1^2 + #1^3 &, 3], Root[2 - #1 - #1^2 + #1^3 &, 2], Root[2 - #1 - #1^2 + #1^3 &, 1]}, {-1, 1, 1}, {1/2 (1 + Sqrt[5]), 1/2 (1 - Sqrt[5]), 0}, {-Sqrt[2], Sqrt[2], 1}, {Root[1 - 2 #1 - #1^2 + #1^3 &, 3], Root[1 - 2 #1 - #1^2 + #1^3 &, 1], Root[1 - 2 #1 - #1^2 + #1^3 &, 2]}, {2, -1, 0}}

You can also work with L to get an 3X3X3 array of eigenvalues as follows:

H1 = Map[Eigenvalues, L, {3}]; 
H2 = Table[Eigenvalues@{{a, b, c}, {1, 0, 1}, {0, 1, 0}}, {a, -1, 1, 1}, 
 {b, -1, 1, 1}, {c, -1, 1, 1}];
H3 = Outer[Eigenvalues[{{##}, {1, 0, 1}, {0, 1, 0}}] &,
  {-1, 0, 1}, {-1, 0, 1}, {-1, 0, 1}];
H1 == H2 == H3

True

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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