# Mathematica 8.0 - Generating List of Powers of Matrices/Graphs

1. Nov 9, 2012

### IBeBananaMan

Hello.

I'm trying to consider a matrix A and looking at Ak and (Ak)TAk, where T is the usual transpose.

This is no big deal. But I'd rather not look at them one at a time--I want to consider some powers k from 1 through as high as I want them. When I try

Code (Text):
Table[MatrixPower[A, k],{k,5}]//MatrixForm
it gives me this giant matrix of each matrix I want, sure, but the matrices are all broken up into column vectors. How can I fix this so I can get a good table of separated matrices (changing MatrixForm to TableForm gives me the view I want, but the matrix brackets are gone so it's just a generic tableau).

Now that's the first issue. My next issue is I would like to take every nonzero element in each matrix and turn it into the value 1.

For just one matrix, I have this

Code (Text):
For[i = 1, i < n + 1, i++,
For[j = 1, j < n + 1, j++,
If[MatrixPower[A, k][[i, j]] == 0, AAl[i, j] := 0,
AAl[i, j] := 1]]];
Which gives me what I want (the matrix Ak will have nonnegative integers for what I'm dealing with, so I can just look for the 0s of my Ak and force every other element = 1). But I'd like to incorporate that into my table of all matrices so I can compute this for all powers simultaneously (it doesn't matter if, say, Ak's values are 0s and 1s and then the next Ak+1 is computed from the modified Ak instead of from the original Ak).

Finally, I'd like to turn all these into adjacency graphs and thus see how the adjacency graph changes with each power. From the above, I simply do

Code (Text):
AA := Table[AAl[i, j], {i, n}, {j, n}];
to create the matrix from the values of the for loop and then finally

Code (Text):
AdjacencyGraph[AA, VertexLabels -> "Name", ImagePadding -> 10]
to see the adjacency graph, and obviously this only works for one matrix power at a time.

Any help would be appreciated. And if there is a better way of dealing with this (I just assume I HAVE to convert my nonzero values to 1 for Mathematica to spit out any adjacency matrix), that would be appreciated.

For reference, I'm looking at Wielandt matrices of order n (which I fix, and I will look at one order at a time), and I'm trying to look at the pattern of the adjacency graphs for finding minimal scrambling and regularity indices (which are the exponents k).

Thanks!

2. Nov 11, 2012

### Hepth

Code (Text):

TableForm[Table[MatrixForm[MatrixPower[A, k]], {k, 5}]]

and
Code (Text):

tabs = Table[MatrixPower[A, k], {k, 5}]
newtable=TableForm[Table[MatrixForm[Table[tabs[[i]][[j, k]] /. {a_ :> If[a == 0, 0, 1]}, {j, 1, Length[A]}, {k, 1, Length[A]}]], {i, 1, Length[tabs]}]]

getting rid of the matrixform and tableform when you need to do actual calculations.

3. Nov 11, 2012

### IBeBananaMan

Wow, thanks a bunch! Not only did you do it, but by replacing MatrixForm with AdjacencyGraph in your second code gives me the graphs I'm looking for (typing this for reference in case anyone else is fooling around with adjacency graphs/matrices). Problem solved!

4. Nov 11, 2012

### Hepth

No problem! I'm sorry I wasn't able to type up more, it was late at night and I was distracted watching a movie, and figured you knew enough that you'd be able to figure out what I did!