Does the product of three matrices end with an odd block matrix?

In the next bit of math code

a1 = {{0, -I}, {I, 0}} a2 = {{0, 1}, {1, 0}} a3 = {{1, 0}, {0, -1}} c = I*a1*a2 // MatrixForm d = c*a3 // MatrixForm 

The mapping d is displayed as two or two matrices, where the elements 1,1 and 2,2 are themselves 2x2 matrices, whereas I expect this to be a simple old 2x2 jump matrix?

+4
source share
2 answers
 use () to protect expression from MatrixFrom which is a wrapper. use '.' for matrix multiplication. Not '*' a1 = {{0, -I}, {I, 0}} a2 = {{0, 1}, {1, 0}} a3 = {{1, 0}, {0, -1}} (c = I a1.a2) // MatrixForm (d = c.a3) // MatrixForm 

This is the result I get for d:

 (1 0 0 1) 
+5
source

This is one of the classic mistakes in Mathematica.

The MatrixForm display MatrixForm takes precedence over the Set ( = ) statement.

Assuming (based on your tag selection) that you wanted to use Dot ( . ) Matrix multiplication instead of Times ( * ), I would write

 a1 = {{0, -I}, {I, 0}} a2 = {{0, 1}, {1, 0}} a3 = {{1, 0}, {0, -1}} (c = I a1.a2) // MatrixForm (d = c.a3) // MatrixForm 

which returns for c and d respectively:

 (1 0 0 -1) (1 0 0 1) 

Edit:
I forgot to mention if you enter

 c = I a1.a2 // MatrixForm 

Then a quick look at FullForm c will show you what the problem is:

 In[6]:= FullForm[c] Out[6]//FullForm= MatrixForm[List[List[1,0],List[0,-1]]] 

You can see that it has Head[c] == MatrixForm , and therefore it will not play well with other matrices.

+5
source

All Articles