1
$\begingroup$

How can a matrix A[n] of size $2^n \times 2^n$ be defined given that

A[1]= {{1, -1}, {1, 1}}

and for $n \ge 1$,

A[n + 1] = {{A[n], -A[n]}, {A[n], A[n]}}

I tried to use SparseArray and assigned the values, but it's limited to set of values I can assign, which doesn't work. Also, I thought to try this : setting a size s= 2^n and then using it in a array x = Array[n, {s, s}], but I get stuck on how to set the elements to 1 and -1.

Can you please guide me in right direction or tell me if I'm going in the wrong direction?

$\endgroup$
  • $\begingroup$ Look up ArrayFlatten $\endgroup$ – Szabolcs Oct 12 '17 at 12:14
  • $\begingroup$ But how can the sequence be defined? Have to do something with 2^n-1 $\endgroup$ – Ahmed Oct 12 '17 at 12:17
1
$\begingroup$
A[1] = {{1, -1}, {1, 1}}
A[n_] := A[n] = ArrayFlatten[{{A[n - 1], -A[n - 1]}, {A[n - 1], A[n - 1]}}]
(* {{1, -1}, {1, 1}} *)

A[5] // MatrixPlot

enter image description here

References:

$\endgroup$
1
$\begingroup$

KroneckerProduct[] is the more natural function to use for generating Walsh-like matrices:

mat = {{1, -1}, {1, 1}};
amat[n_Integer?NonNegative] := Nest[KroneckerProduct[mat, #] &, mat, n - 1]

MatrixPlot[amat[5]]

Walsh matrix

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.