How to Transform a Matrix in Mathematica?

  • Context: Mathematica 
  • Thread starter Thread starter guerom00
  • Start date Start date
  • Tags Tags
    Mathematica Matrix
Click For Summary

Discussion Overview

The discussion revolves around transforming a matrix in Mathematica, specifically how to rearrange elements and insert zeros to achieve a desired format. The conversation includes technical approaches, potential functions, and alternative methods related to matrix manipulation.

Discussion Character

  • Technical explanation
  • Exploratory
  • Mathematical reasoning

Main Points Raised

  • One participant seeks to transform a matrix by permuting rows and columns while inserting zeros, expressing difficulty in finding a suitable function in Mathematica.
  • Another participant suggests that the transformation can be achieved by permuting rows and columns of the original matrix.
  • A different approach is proposed involving the tensor product of two matrices, with one participant noting uncertainty about the availability of this function in newer versions of Mathematica.
  • Another participant mentions using the Outer function for tensor products and corrects a previous statement regarding matrix operations.
  • A participant expresses interest in a general thread for Mathematica questions and seeks assistance with a pattern matching problem related to lists of zeros.

Areas of Agreement / Disagreement

Participants present multiple approaches to the matrix transformation, with no consensus on a single method or solution. The discussion remains unresolved regarding the most elegant or effective technique.

Contextual Notes

Some participants reference specific functions and operations in Mathematica, but there is no agreement on the best approach to achieve the desired matrix transformation. The discussion includes various assumptions about the capabilities of Mathematica and the definitions of matrix operations.

guerom00
Messages
90
Reaction score
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
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:
 


Thanks for your response :smile:

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


I found this which is not bad :

eam4ae.jpg


:smile:
 


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.
 


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:


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


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
 

Similar threads

  • · Replies 6 ·
Replies
6
Views
7K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
Replies
2
Views
2K