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

  • Thread starter Thread starter IBeBananaMan
  • Start date Start date
  • Tags Tags
    List Mathematica
AI Thread Summary
The discussion revolves around generating a list of powers of a matrix A in Mathematica and formatting them for better visualization. The user seeks to create a table of matrices from powers Ak without the matrices being broken into column vectors. They also want to convert all nonzero elements of each matrix to 1 for further analysis, specifically for creating adjacency graphs. A solution was found that involves using TableForm and AdjacencyGraph to achieve the desired output for multiple matrix powers simultaneously. The user expresses satisfaction with the resolution and acknowledges the effectiveness of the provided code.
IBeBananaMan
Messages
2
Reaction score
0
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:
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:
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:
AA := Table[AAl[i, j], {i, n}, {j, n}];

to create the matrix from the values of the for loop and then finally

Code:
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!
 
Physics news on Phys.org
Code:
TableForm[Table[MatrixForm[MatrixPower[A, k]], {k, 5}]]
and
Code:
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.
 
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!
 
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!
 

Similar threads

Replies
1
Views
1K
Replies
1
Views
2K
Replies
1
Views
5K
Replies
3
Views
2K
Replies
2
Views
3K
Replies
2
Views
3K
Back
Top