Question related to matrix in computer memory

1.3k Views Asked by At

I'm trying to solve the following problem from a book:

A matrix $\mathbb M$ has 3 rows and 4 columns:

$$\left[ \begin{array}{cccc} a_{11} & a_{12} & a_{13} & a_{14}\\ a_{21} & a_{22} & a_{23} & a_{24}\\ a_{31} & a_{32} & a_{33} & a_{34}\\ \end{array} \right]$$

The 12 entries in the matrix are to be stored in row major form in locations 7,609 to 7,620 in a computer’s memory. This means that the entries in the first row (reading left to right) are stored first, then the entries in the second row, and finally the entries in the third row. Find formulas (in $n$) for $r$ and $s$ so that $a_{rs}$ is stored in location 7,609 + $n$.

So far I have come up with this relation among $r$, $s$ and $n$ (which is fairly common in matrix calculations):

$$4 \cdot (r-1) + s - 1 = n$$

But I can't seem to find the second relation that will allow me to express $r$ and $s$ in terms of $n$. Any help is greatly appreciated.

1

There are 1 best solutions below

2
On BEST ANSWER

For the rows, we want to come up with a function that will map $\{0,1,2,3\}$ to $1$, $\{4,5,6,7\}$ to $2$, and $\{8,9,10,11\}$ to $3$. This suggests that we use a floor function as follows: $$ r=1+\lfloor n/4 \rfloor $$


For the columns, we want to come up with a function that will map $\{0,4,8\}$ to $1$, $\{1,5,9\}$ to $2$, $\{2,6,10\}$ to $3$, and $\{3,7,11\}$ to $4$. This suggests that we take the remainder as follows: $$ s=1+(n \bmod 4) $$