Inserting random numbers from 1 to $n^2$ in a matrix of size $n \times n$

102 Views Asked by At

I have two matrices of size nxn with random numbers that are in range of $1$ to $n^2$. I'm trying to calculate the probability of :

  1. the numbers 1 and 9 are present in the same indices in the two matrices,for example($n=4$): \begin{bmatrix} 14& 10 & 2 & 1 \\ 11& \textbf{1} & 16 & 15 \\ 4 & 9& 13 & \textbf{9}\\ 6 & 3& 5 & 7\\ \end{bmatrix} \begin{bmatrix} 13& 4& 2 & 7 \\ 15& \textbf{1} & 11& 10\\ 6 & 16& 5& \textbf{9}\\ 12 & 8& 3 & 14\\ \end{bmatrix}
  2. A pair (one or more) of two numbers that are sequential that exist in the same index of the two matrices. for example(n=4): \begin{bmatrix} 14& 10 & 2 & 1 \\ 11& 1 & 16 & 15 \\ 4 & 9& 13 & \textbf{6}\\ 6 & 3& \textbf{5} & 7\\ \end{bmatrix} \begin{bmatrix} 13& 4& 2 & 7 \\ 15& 3 & 11& 10\\ 6 & 16& 2& \textbf{6}\\ 12 & 8& \textbf{5} & 14\\ \end{bmatrix}
  3. Row values of the first matrix are equal to the row values of the second matrix (not necessarily in the same index values) ,example(n=4): \begin{bmatrix} 14& 10 & 2 & 8 \\ 11& 1 & 16 & 15 \\ 4 & 12& 9& 6\\ 13 & 3& 5 & 7\\ \end{bmatrix} \begin{bmatrix} 10& 2& 8 & 14 \\ 16& 11 & 15& 1\\ 6 & 9& 4& 12\\ 13 & 3& 7 & 5\\ \end{bmatrix}
1

There are 1 best solutions below

4
On BEST ANSWER

I'll solve the first part of the problem and leave the rest for you to solve

First place 1 and 9 at any two locations out of $n^2$ available locations. Then fill the rest of $2n^2-4$ with any number between 1 and $n^2$. So the total number of desired possibilities $=^{n^2}\!\!\!P_{2}(n^2)^{2n^2-4}$.

The number of possible matrix pairs without any restrictions is $(n^2)^{2n^2}$.

Hence the probability is $\frac{n^2-1}{n^6}$