Question: 4 Problem 2 : Matrix Diagonal Sums 4 . 1 Overview A problem that occasionally arises in numerical computing when working with Matrices ( 2

4 Problem 2: Matrix Diagonal Sums
4.1 Overview
A problem that occasionally arises in numerical computing when working with Matrices (2D Arrays) is to compute the sums of the Diagonals of a matrix. The main diagonal of a matrix is comprised of all elements at indices (0,0),(1,1),(2,2), and so forth. There are several numbering schemes for diagonals but we will use the one represented in the following diagram which also shows the sums of the diagonal
A code is provided in the file sumdiag_base.c which computes the sums of diagonals and stores them in a vector. The algorithm does so using the most "natural" approach of walking down each diagonal and totaling its elements then storing the result in the associated vector element. As you survey the code, note the use of various convenience functions such as mget(mat,i,j) and vset(vec,i,x) to interact with the matrix and vector types used.
int sumdiag_BASE_NORMAL(matrix_t mat, vector_t vec){
if(vec.len !=(mat.rows + mat.cols -1)){
printf("sumdiag_base: bad sizes
");
return 1;
}
for(int i=0; i

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!