Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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) $$

share|improve this answer
    
Wow! Thanks so much! I did try all this while to find out a relation. I was trying variations of $\lfloor n/4 \rfloor + 1 - (-1)^n$, which was of course not working. In retrospect, it should have been easy to anticipate the functions, given that this chapter had introduced div and mod. :) –  dotslash Jul 18 '13 at 5:05
1  
Also formally (using $0\le s-1<4$) we have $\lfloor\frac{4(r-1)+(s-1)}{4}\rfloor =r-1$ and $4(r-1)+(s-1)\equiv s-1\pmod 4$ –  Hagen von Eitzen Jul 18 '13 at 5:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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