Note the due date of this program. It is important that you meet this
date. The mid-term exam will be in class (open notes, open book) on
April 16th and will cover Chapters 1-6.
The assignment is to write four matrix routines and a main program which
tests the routines. The four functions should each be in their own
files and a header file should be included as well. The functions
are designed to work with two-dimensional matrices that have been
declared in the "traditional" way (e.g. double M[nrows][ncols];).
The prototypes for the functions are given below:
1. void matrix_copy (double *A, double *B, int nrows, int ncols);
/* copies the matrix B to the matrix A (dimensions of the two */
/* matrices are both nrows x ncols ) */
2. void matrix_add (double *A, double *B1, double *B2,
int nrows, int ncols);
/* adds matrix B1 to matrix B2 and places result in A */
3. void matrix_slice (double *slice, double *A, int j,
int nrows, int ncols, int rc_flag);
/* copies the jth row (or the jth column) of the matrix A into the */
/* vector slice. rc_flag indicates row or column operation */
/* if rc_flag == 1 copy jth row */
/* if rc_flag == 2 copy jth column */
4. void matrix_print (double *A, int nrows, int ncols,
int width, int precision);
/* prints the matrix A by rows and uses width and precision for */
/* output format of each matrix entry. See use of "%*.*f" on page */
/* 497 of the text */
Suggestion: After you are happy with your program, swap your main
program (the test driver) with another team and see if your code
compiles and runs correctly with their driver.
Sample PORTION of code for testing:
double m1[3][7] = {1.0,2.0,3.0,4.0,5.0,6.0};
double m2[3][7];
printf ("Original Matrix \n");
matrix_print (m1, 3, 7, 8, 2);
matrix_copy (m2, m1, 3, 7);
printf ("Copied Matrix \n");
matrix_print (m2, 3, 7, 8, 2);