Mathematica 8.0 - Generating List of Powers of Matrices/Graphs

  • Context: Mathematica 
  • Thread starter Thread starter IBeBananaMan
  • Start date Start date
  • Tags Tags
    List Mathematica
Click For Summary

Discussion Overview

The discussion revolves around generating and visualizing powers of matrices using Mathematica, specifically focusing on transforming these matrices into adjacency graphs. Participants explore methods to create a table of matrix powers, modify matrix elements, and visualize the resulting graphs.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Experimental/applied

Main Points Raised

  • One participant seeks to generate a table of matrix powers and is facing issues with the output format when using MatrixForm.
  • Another participant suggests using TableForm to achieve a more desirable layout for the matrices.
  • A participant expresses the need to convert all nonzero elements of the matrices to 1 and shares a method using nested loops to accomplish this for a single matrix.
  • There is a discussion on how to apply the transformation to all matrix powers simultaneously, with one participant asking for a more efficient method.
  • One participant mentions the goal of visualizing adjacency graphs based on the modified matrices and shares their approach to create these graphs using AdjacencyGraph.
  • Another participant acknowledges the solution provided and notes the effectiveness of replacing MatrixForm with AdjacencyGraph for their needs.

Areas of Agreement / Disagreement

Participants generally agree on the methods discussed for generating matrix powers and visualizing them as adjacency graphs, but there is no consensus on the most efficient way to modify the matrices for all powers simultaneously.

Contextual Notes

Some limitations include the dependence on the specific structure of the matrices being used and the potential need for further optimization in the code provided for handling multiple matrix transformations.

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 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
7K