[Mathematica] Explose a matrix

In summary, the conversation is about how to "explose" or transform a matrix by permuting its rows and columns. The second matrix is essentially the top left corner of the first matrix, with zero rows and columns inserted. Possible solutions include using ArrayPad or Outer[Times] to perform tensor products. The conversation also touches on finding a pattern to match a list of zeros of arbitrary length.
  • #1
guerom00
93
0
[Mathematica] “Explose” a matrix

Hi all,

Sorry for the title :biggrin:
Here is what I need to do : Transform this matrix (sorry, didn't find the LaTeX for matrices; pmatrix does not work)

a b c 0 0 0 0 0 0
d e f 0 0 0 0 0 0
g h i 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

into


a 0 0 b 0 0 c 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
d 0 0 e 0 0 f 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
g 0 0 h 0 0 i 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

if you see what I mean… I looked into ArrayPad[] but my pattern is more complicated than a simple padding…
What's the best solution do that ?

TIA
 
Last edited:
Physics news on Phys.org
  • #2
Hi guerom00! :smile:

The second matrix is the same as the top left corner of the first matrix, but with lots of zero rows and columns inserted.

So just permute the rows, and permute the columns. :smile:
 
  • #3


Thanks for your response :smile:

Yeah… How to permute 2 rows or 2 columns ?
Nothing more “elegant” ?
 
  • #4


I found this which is not bad :

eam4ae.jpg


:smile:
 
  • #5


If

A={{1,0,0},{0,0,0},{0,0,0}}
B={{a,b,c},{d,e,f},{g,h,i}}

then your first matrix is A x B and your second matrix is B x A, where "x" means tensor product. I'm not sure if new versions of Mathematica have the "tensor product" implemented, I already use an old code made by myself for that.
 
  • #6


I know if you have two matrices you can do:

A = {{a, b}, {c, d}}
B = {{1, 0, 0}, {0, 0, 0}, {0, 0, 0}}
Outer[Times, A, B] // ArrayFlattenI think by tensor product you mean outer product.EDIT: Changed SUM to Times (I had some for something else I was trying, TIMES is what you want.)
 
Last edited:
  • #7


Yes, Outer[Times[]] works for tensor products of matrices.
What I use does not need ArrayFlatten...
 
  • #8


Thanks :smile:

Is there a general thread for random questions on Mathematica ? I don't want to open a new thread each time…
For instance, I'm looking for a pattern (to be used in a DeleteCases[]) which match a list of zeros of arbitrary length i.e. which match {0} or {0,0} or {0,0,0}, etc…
Can someone help me ?

TIA
 

What is a matrix explosion in Mathematica?

A matrix explosion in Mathematica is the process of expanding a matrix into its individual elements. This can be done by using the Flatten function or the MatrixForm function.

How do I explose a matrix in Mathematica?

To explose a matrix in Mathematica, you can use the Flatten function or the MatrixForm function. The Flatten function will convert the matrix into a list of its individual elements, while the MatrixForm function will display the matrix in a grid format.

Can I explose a specific element of a matrix in Mathematica?

Yes, you can explose a specific element of a matrix in Mathematica by using the Part function. This function allows you to specify the position of the element within the matrix and extract it.

Is there a limit to the size of a matrix that can be exploded in Mathematica?

There is no specific limit to the size of a matrix that can be exploded in Mathematica. However, for larger matrices, the process may take longer to complete and may require more computational resources.

Can I undo a matrix explosion in Mathematica?

No, once a matrix has been exploded in Mathematica, it cannot be undone. However, you can use the Reverse function to reverse the order of the elements in the list obtained from the explosion process to get back the original matrix.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • Advanced Physics Homework Help
Replies
8
Views
732
  • Precalculus Mathematics Homework Help
Replies
1
Views
725
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • Calculus and Beyond Homework Help
Replies
6
Views
295
Replies
6
Views
1K
Replies
2
Views
785
Back
Top