hey,
im working on a function for creating n-size hadamard matrices (instead of storing them all in a dictionary).
i think i got the formula already.
but i would like to type in ~getHadamard.(2) for a 2x2 matrix, ~getHadamard.(4) for a 4x4 matrix, ~getHadamard.(n) for a nxn matrix. does somebody know how to adjust n so the function is giving the desired result? if i type in ~getHadamard.(2) or ~getHadamard.(4) the result seems correct.
but for ~getHadamard.(8) the matrix.size = 16 not 8. thanks
still having a hard time with iteration. here is the code:
Is it necessary at all to multiply within the loop?
If you take matrix = matrix * sqrt(order).reciprocal; outside of n.do then you get a matrix of +/- 1.
If you take this result and multiply by the desired final magnitude, then you get what you want with less work (and less complication = less debugging).
Otherwise, if you really want to do it this way, consider that the final result of multiplying +/-1 by sqrt(order).reciprocal /n/ times is to multiply by sqrt(order).reciprocal ** n.
Algebra again:
sqrt(order).reciprocal ** n
(order ** (1/2)).reciprocal ** n
((order ** (1/2)) ** -1) ** n // and now multiply exponents
order ** (n.neg/2)
// If order = 8, n = log2(8) - 1 = 2 so
8 ** (-2/2) == 8 ** (-1) == 0.125
If that’s not what you want, then the iterative formula needs to change.