Question: Here is the Code file .C /* asg3.c, Currently progam has functions for dynamic allocation of 2D dimensional arrays and initializes matrices You need to

Here is the Code file .C /* asg3.c, Currently progam has functionsHere is the Code file .C

/* asg3.c, 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

/* 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

}

Option 2: Complete the C program asg3.c A common problem in statistics is to perform Linear Regression on multiple independent variables. The independent variable data in a matrix A with a lot of rows (observations), with relatively few columns (independent variable values x_1,x_2,...,x_m for each observation). In summary, A will m sample points (rows), where each sample point has m numbers associated with it. To get the linear regression coefficients, the first and most expensive!) calculation is to compute the matrix At A and store it as some variable (e.g. C=A? A). Then given a response vector y,the system of equations CB=A*y is solved for . 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) 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 2: Complete the C program asg3.c A common problem in statistics is to perform Linear Regression on multiple independent variables. The independent variable data in a matrix A with a lot of rows (observations), with relatively few columns (independent variable values x_1,x_2,...,x_m for each observation). In summary, A will m sample points (rows), where each sample point has m numbers associated with it. To get the linear regression coefficients, the first and most expensive!) calculation is to compute the matrix At A and store it as some variable (e.g. C=A? A). Then given a response vector y,the system of equations CB=A*y is solved for . 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) 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!