1
$\begingroup$

At present, I want to generate some random matrices whose nth power is zero matrix.

mat0[n_] := 
 Module[{k}, 
  While[MatrixPower[k = RandomInteger[{1, 5}, {n, n}], 3] =!= 
    ConstantArray[0, {n, n}]]; k]
MatrixPower[#, 3] & /@ Table[mat0[3], 3]

A = Array[x, {3, 3}];
FindInstance[MatrixPower[A, 3] == ConstantArray[0, {3, 3}], 
 Flatten[A], Reals, 3]

The above code is used to get the matrix whose third power is zero matrix. But the above code has been running, what can I do to quickly get the random matrix that meets the requirements?

$\endgroup$

1 Answer 1

2
$\begingroup$

I make no claims whatsoever on the distribution followed by the matrices generated by the following routine:

randomNilpotentMatrix[n_Integer?Positive, p_Integer?Positive] := 
      With[{uf = First[HermiteDecomposition[RandomInteger[{-9, 9}, {n, n}]]]}, 
           LinearSolve[uf, SparseArray[{Band[{1, 2}] -> ConstantArray[1, Min[p, n] - 1]},
                                       {n, n}]].uf]

For instance,

BlockRandom[SeedRandom[42]; randomNilpotentMatrix[3, 3]]
   {{73, 109, -116}, {283, 419, -444}, {313, 464, -492}}

MatrixPower[%, 3]
   {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}
   {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}
$\endgroup$
5
  • $\begingroup$ Thank you very much. How to modify your code to generate a matrix whose power of 4 is not zero matrix but whose power is 5 is zero matrix? $\endgroup$ Aug 14, 2020 at 1:49
  • $\begingroup$ Try randomNilpotentMatrix[5, 5]. $\endgroup$ Aug 14, 2020 at 1:51
  • $\begingroup$ Is it possible to generate a 3 * 3 matrix whose 4th power is not zero matrix but its 5th power is zero matrix? $\endgroup$ Aug 14, 2020 at 1:54
  • 1
    $\begingroup$ It's a good linear algebraic exercise for you to prove that your request is unreasonable. $\endgroup$ Aug 14, 2020 at 1:56
  • $\begingroup$ Thank you very much. According to the Hamilton-Cayley theorem, we can know that the nilpotent exponent is not greater than the order of the matrix. $\endgroup$ Aug 14, 2020 at 2:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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