I'm trying to build a function that gives me matrices such that each:
- Has integer coefficients.
- Is non singular.
- Has inverse which also has integer coefficients.
I have some code that one of my teachers gave me, but it is code written in Derive. I have reproduced the code, but I'm not getting what a really need.
The code for Derive requires a function that takes a column, multiplies it by a constant and adds it to another one, lest call this function ColSum[M, i, j, α]
, which takes the i-th column multiplied by α and adds it to the j-th column.
The code for the matrix in Derive is:
Matrix(n) ≔
\prod_{h=1}^{n-1} \prod_{k=h+1}^{n} ColSum(IDENTITYMATRIX(n), h, k, (1 + RANDOM(2))·(-1)^h)*
\prod_{k=1}^{n-1} \prod_{h=k+1}^{n} ColSum(IDENTITYMATRIX(n), k, h, (1 + RANDOM(2))·(-1)^k)*
VECTOR(VECTOR(IF(i_ < j_, 0, IF(i_ = j_, (-1), RANDOM(2) + 1)), i_, 1, n_), j_, 1, n_)
I think the problem is either in the ColSum
function because it is where I've seen that things go wrong, or in the fact that Product
does not perform an iterated Dot
.
I want to translate this function into Mathematica.
My code so far is:
RowSum[v_,i_,j_,a_] := Table[If[m ==i , Part[v,i] + a*Part[v,j],Part[v,m]],{m,Dimensions[v][[1]]}]
ColSum[v_,i_,j_,a_]:=Transpose[RowSum[Transpose[v],i,j,a]]]
Matrix[n_] := Product[ColSum[IdentityMatrix[n], h, k, (1 + RandomInteger[2])*(-1)^h ], {h,1, n - 1}, {k, h + 1,n}].Product[ColSum[IdentityMatrix[n], k, h, (1 + RandomInteger[2])*(-1)^k ], {k, 1, n - 1}, {h, k + 1, n}].Table[Table[If[i < j, 0, If[i == j, (-1)^i,RandomInteger[2] + 1]], {i, n}], {j, n}]
I think the problem is either in the ColSum
function because it is where I've seen that things go wrong, or in the fact that Product
does not perform an iterated Dot
.
Thanks for helping.
Product[...]
$\endgroup$