Question: Currently, the program has functions for dynamic allocation of 2D dimensional arrays and initializes matrices You need to the multiplication A^T A, with the result

 Currently, the program has functions for dynamic allocation of 2D dimensional

Currently, the program has functions for dynamic allocation of 2D dimensional arrays and initializes matrices You need to the multiplication A^T A, with the result stored in C

Here is the code in .C:

#include #include #include

/* Function Prototypes */ void fillMatrixValues(float **, float **, int, int); float **allocateMatrix(int, int); void freeMatrix(float **,int); /* See Function Definitons below main

/* START MAIN */ int main(void) {

int m,n; clock_t begin, end; double timeSpent;

int row,col,k;

/*Get User Input on Matrix Dimension and Allocate Memory For Matrices*/ printf(" What is the matrix row dimension? "); scanf("%d",&m); printf("What is the matrix column dimension? "); scanf("%d",&n); float **A = allocateMatrix(m,n); float **C = allocateMatrix(n,n); printf(" Memory Allocated for A,C ");

/* Fill out the matrices A,C */ fillMatrixValues(A,C,m,n); printf("A, C now initialized. "); /* Matrix Definiton Routine is Finished */ begin = clock();

/* DO THE MATRIX MULT LOOPS HERE or Call the Matrix Mult Function Here */

end = clock(); if (n>2) { printf("Row 1 (first 3 entries): %8.4f, %8.4f, %8.4f ",C[0][0],C[0][1],C[0][2]); printf("Row 2 (first 3 entries): %8.4f, %8.4f, %8.4f ",C[1][0],C[1][1],C[1][2]); printf("Row 3 (first 3 entries): %8.4f, %8.4f, %8.4f ",C[2][0],C[2][1],C[2][2]); } timeSpent = (double)(end - begin) / CLOCKS_PER_SEC; printf("Matrix Mult Time: %.3e ",timeSpent); /* Deallocate Pointers */ printf("Deallocating Memory for A,C "); freeMatrix(A,m); freeMatrix(C,n); /* Finished DeAllocation */ printf("Press any key to end this madness. "); getch(); return (0);

}

/* Function for allocating a matrix of float */ float **allocateMatrix(int nRows,int nCols) { int row; float **M; /* variable declaration */

/* Dynamic Allocation of Matrix M using malloc */ M = (float **) malloc( nRows* sizeof (float*) ); for (row=0;row

/* Function for Freeing 2D arrays */ void freeMatrix(float **M,int nRows) { int row; for(row=0; row

void fillMatrixValues( float **A, float **B,int m, int n) { int row, col; float top,bot; for(row=0;row

}

Your Job: Perform the multiplication . C=A" A Necessary Features (Get the right answer! 7 pts) Multiply AT A and store the result in C Additional Features (2 pts) Incorporate the matrix multiplication inside of a function. i.e. create a function called LRmult that accepts matrix A and the dimensions m,n, as arguments (and maybe B too?), and performs the required multiplicaiton (2pts) Nested Loop order is optimized for speed (1pt)

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!