0

I am new to Mathematica and try to define a simple recursive formula which is illustrated as below:

A[1] := {{0, 0}, {0, 0}} // MatrixForm;
identity := {{1, 0}, {0, 1}};
A[n_] := KroneckerProduct[identity, A[n - 1]];
A[2] // MatrixForm

The result is expected to be a zero matrix with size 4$\times$4, i.e.

$$ \begin{pmatrix} 0&0&0&0\\ 0&0&0&0\\ 0&0&0&0\\ 0&0&0&0 \end{pmatrix} $$

if I let n=2. However, the returned result is

$$ \begin{pmatrix} 0&0&0&1\\ 0&0&1&0\\ 0&1&0&0\\ 1&0&0&0 \end{pmatrix} $$

I have checked many times but still don't know what's the error for my code. Could anyone give some hints?

mattiav27
  • 6,677
  • 3
  • 28
  • 64
user81752
  • 19
  • 3

1 Answers1

2

Notice use of parentheses on line 1 and also on line 4. MatrixForm outputs cannot be used in computations.

(A[1] := {{0, 0}, {0, 0}}) // MatrixForm;
identity := {{1, 0}, {0, 1}};
A[n_] := KroneckerProduct[identity, A[n - 1]];
(A[2]) // MatrixForm

\begin{array}{cccc} 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 \\ \end{array}

Syed
  • 52,495
  • 4
  • 30
  • 85