3

I have been going though some matrix multiplication problem and there I faced this kind of problem where I am trying to show the whole multiplication form in the next line of H.S.T.H.zero // MatrixForm but it's not working and I have to put all the matrix elements manually.

zero = {{1}, {0}} // MatrixForm
H = 1/sqrt[2] {{1, 1}, {1, -1}} // MatrixForm
S = {{1, 0}, {0, I}} // MatrixForm
T = {{1, 0}, {0 , E^(I Pi/4)}} // MatrixForm
H.S.T.H.zero // MatrixForm

the output it's showing ---> The output that is showing

But the output I want -----> Desired output

If there any way to solve this please let me know! I would be very greatful.

2 Answers2

4
$Version

(* "13.1.0 for Mac OS X x86 (64-bit) (June 16, 2022)" *)

Clear["Global`*"]

sqrt should be Sqrt. All built-in functions start with a capital letter.

zero = {{1}, {0}};
H = 1/Sqrt[2] {{1, 1}, {1, -1}};
S = {{1, 0}, {0, I}};
T = {{1, 0}, {0, E^(I Pi/4)}};
(eqn = Inactivate[(H . S . T . H . zero), Dot] == 
    Simplify[H . S . T . H . zero]) /. mat_?MatrixQ :> MatrixForm[mat]

enter image description here

Activate@eqn

(* True *)

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
1

if you like Latex, you could also use Matex package.

<< MaTeX`
SetOptions[MaTeX, Magnification -> 2]

zero = {{1}, {0}} H = 1/Sqrt[2] {{1, 1}, {1, -1}} S = {{1, 0}, {0, I}} T = {{1, 0}, {0, E^(I Pi/4)}} result = H . S . T . H . zero

And now

Row[{MaTeX[MatrixForm@H],
  MaTeX[MatrixForm@S],
  MaTeX[MatrixForm@T],
  MaTeX[MatrixForm@H],
  MaTeX[MatrixForm@zero],
  MaTeX["="],
  MaTeX[MatrixForm@result]
  }]

enter image description here

If you want an explicit multiplication between them, (even though I do not think it is needed) you can do

Row[{MaTeX[MatrixForm@H],
  MaTeX["\\times"],
  MaTeX[MatrixForm@S],
  MaTeX["\\times"],
  MaTeX[MatrixForm@T],
  MaTeX["\\times"],
  MaTeX[MatrixForm@H],
  MaTeX["\\times"],
  MaTeX[MatrixForm@zero],
  MaTeX["="],
  MaTeX[MatrixForm@result]
  }]

enter image description here

But if you prefer dot for multiplication

Row[{MaTeX[MatrixForm@H],
  MaTeX["\\cdot"],
  MaTeX[MatrixForm@S],
  MaTeX["\\cdot"],
  MaTeX[MatrixForm@T],
  MaTeX["\\cdot"],
  MaTeX[MatrixForm@H],
  MaTeX["\\cdot"],
  MaTeX[MatrixForm@zero],
  MaTeX["="],
  MaTeX[MatrixForm@result]
  }]

enter image description here

Nasser
  • 143,286
  • 11
  • 154
  • 359