A matrix A has 3 rows and 4 columns:
a11 a12 a13 a14
a21 a22 a23 a24
a31 a32 a33 a34
The 12 entries in the matrix are to be stored in row major form in locations 7609 to 7620 in a computer’s memory. This means that the entires in the first row (reading left to right) are stored first, then entries in the second row, and finally entries in the third row.
Which location with a22 be stored in?
Write a formula in i and j that gives the integer n so that aij is stored in location 7609 + n.
Find formulas in n for r and s so that ars is stored in location 7609 + n.
Now generalize! Let M be a matrix with m rows and n columns, and suppose that the entries are stored in the computer’s memory in row major form in locations N,N +1,N +2,...,N +mn−1. Find formulas in k for r and s so that ars is stored in location N + k.
above image depicts the array. in which the number mentioned above the element is the location where that element is stored in computer's memory in the given question.
now, when we try to find the location of element a22 from the image we can clearly guess it is 7614.
Coming to second part of the question, the formula for finding the address(memory location) of the element aij.
Given location for the first element (a11) is 7609.
and start row index of matrix is 1
and start column index of matrix is 1
So, the formula for finding the address of the matrix is
A[i,j] = Base address + [C * (i-1)+(j-1)]
Here, C is the total number of columns in given matrix.
so the formula for the Given question will be
A[i,j]= Base address + [4 * (i-1) + (j-1)]
Solving for a22 -
a[2,2] = 7609 + [4*(2-1) + (2-1)]
a[2,2] = 7609 + [4*1 + (2-1)]
a[2,2] = 7609 + [4 + (2-1)]
a[2,2] = 7609 + [4 + 1]
a[2,2] = 7609 + 5
So, n=5 here.
a[2,2] = 7614.
Now, coming to 3rd part.
the Formula for the ars element of an array will be
ars = Base address + [C * (r-1)+(s-1)]
Where,
C = number of columns in given matrix.
if we need to calculate for n.
n= [C * (r-1)+(s-1)]
where,
C = number of columns in given matrix.
Now, coming to 4th part.
if, we generalize this formula for Matrix M. having m rows and n columns.
for,
A[ars] = [N + n * (r-Lr) + (s-Lc) ]
where,
N= Base address given in question
n = number of columns in Matrix
Lr= Row index of the Mattrix
Lc= Column index of the Matrix.
For calculating k,
k= n * (r-Lr) + (s-Lc)
where,
n = number of columns in Matrix
Lr= Row index of the Mattrix
Lc= Column index of the Matrix.
Rule of Sarrus for the determinant of 3 x 3-matrices. Let a11 a12 a13 A=|a21 a22 a23 a3i a32 a33 21 22 Prove that Hint: Expand det A across the first row Rule of Sarrus for the determinant of 3 x 3-matrices. Let a11 a12 a13 A=|a21 a22 a23 a3i a32 a33 21 22 Prove that Hint: Expand det A across the first row