Question: It is the problem regrads on C programming. There are 2 parts from the question (a) and (b). Please answer the following quesiton. When 2D

 It is the problem regrads on C programming. There are 2

It is the problem regrads on C programming. There are 2 parts from the question (a) and (b). Please answer the following quesiton. When 2D data is stored on a computer, it is often stored in contiguous memory either row-by-row (as in NumPy and C) or column-by-column (as in R, MatLab, and Fortran). These orderings are called row-major and column-major, respectively. From mathematical notation, you are probably used to accessing 2D data using two indices, e.g., (j, i) to indicate the row and column. We will store our 2D data as a single, large 1D array. For example, if our 2D data is ny x nix, then the 1D array will have length nynz. Your C program will need to compute a pointer to the data in the linear memory. Consider U, an ny x ny matrix, 10.0 U1,0 10,1 U1,1 U0n-1 U1,n,-1 U= (1) : Luny-1,0 Uny-1,1 Uny-1,92-1 If U is stored in row-major form, the equivalent 1D array is given below, with the linear indices shown under each entry. (10,0 Uon-1 U1,0 U1,1 U1,n2-1 Uny-1,0 Uny-1,1 Uny-1,n2-1] 1 0 1 ne - 1 ng 2ng - 1 (ny - 1)nz (ny 1)nz + 1 10,1 ne +1 nyny - 1 (a) If the user wants to access the (j,i) entry of U, the corresponding linear index in row-major form is kr = jn, +i. Justify this expression. (b) Assume that kr is known but (j,i) is not. Give expressions for the (j, i) pair that corresponds to the linear index kr

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!