Question: Here is the code in .C please complete this code. Currently progam has functions for dynamic allocation of 2D dimensional arrays and initializes matrices You


Here is the code in .C please complete this code.
Currently progam has functions for dynamic allocation of 2D dimensional arrays and initializes matrices You need to the multiplication A^T A , with result stored in C Command Line: Compile: gcc asg3.c Run: ./a.out
*/
#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 M[row]=(float*)malloc( nCols* sizeof(float) ); /* End Allocation */ return M; }
/* 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 for(col=0; col { top=(float) (1+row-col); bot= (float) (row*col+1); A[row][col]=top/bot; } for (row=0; row for (col=0;col B[row][col]=0.0;
}
Option 1: Complete the function linearSolve.m in Matlab Necessary Features (Get the right answer! 9pts) Implements Gaussian Elimination with Partial Pivoting If Gaussian Elimination is successful, the solution will be bound with Back Substitution (I have written this part for you!) If Gaussian is unsuccessful (some pivot column has no nonzero pivots available), then the Gaussian Elimination loop is broken and the empty solution x=[ ] is returned and the exit flag is set to O O Additional Features (1 pt) Inner Loop reordering for potential speed up Your Job: Perform the multiplication . C=AA Necessary Features (Get the right answer! 7 pts) Multiply AT A and store the result in C Additional Features (2 pts) O 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) Option 1: Complete the function linearSolve.m in Matlab Necessary Features (Get the right answer! 9pts) Implements Gaussian Elimination with Partial Pivoting If Gaussian Elimination is successful, the solution will be bound with Back Substitution (I have written this part for you!) If Gaussian is unsuccessful (some pivot column has no nonzero pivots available), then the Gaussian Elimination loop is broken and the empty solution x=[ ] is returned and the exit flag is set to O O Additional Features (1 pt) Inner Loop reordering for potential speed up Your Job: Perform the multiplication . C=AA Necessary Features (Get the right answer! 7 pts) Multiply AT A and store the result in C Additional Features (2 pts) O 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
Get step-by-step solutions from verified subject matter experts
