genMatrixMult
in GenMath.lib
Matrix Functions Function List by Category Alphabetical Function List
int genMatrixMult(
float *MatrixA,
// pointer to matrix A array
int dimM,
// row dimension of matrix A
int dimN,
// column dimension of matrix B
float *MatrixB,
// pointer to matrix B array
int dimP,
// common dimension
float *MatrixProd)
// pointer to store product Matrix
This function multiples an mxp matrix by a pxn matrix:
c(i,j) = sum[k=1 .. n] {a(i,k) * b(k,j)}
There is no array bounds checking performed within the function; the user
must ensure that matrices A, B and C are of proper size. Specifically, A
should be an mxp array, B a pxn array and
MatrixProd should be an mxn array.
The
return code is errno, defined in the C standard library (math.h). This is
an integer value
for math errors.
Sample Application:
/////////// splMMnm.c for genMatrixMult Library Function ///////////// // // // For this sample, a 2x3 matrix is multiplied by a 3x2 // // matrix. // // // ////////////////////////////////////////////////////////////////////// //////////////////////////// INCLUDES //////////////////////////////// #include "stdio.h" #include "genMath.h" ////////////////////////////// MAIN ////////////////////////////////// void main() { //local declarations //integers int i; // i dimension counter for result int j; // j dimension counter for result display int retcode; // return code for call to genMatrixMultnxn //floats float a[3][3]; // matrix A float b[3][3]; // matrix B float c[3][3]; // resultant matrix, C //character strings char ch; //input string to exit //intialize the A and B matrices a[0][0] = (float)1.234; a[0][1] = (float)-.678; a[0][2] = (float)10.3;
a[1][0] = (float)14.004; a[1][1] = (float)5.332; a[1][2] = (float)0.004; b[0][0] = (float)4.559; b[0][1] = (float)3.24;
b[1][0] = (float)-6.669; b[1][1] = (float)0.076;
b[2][0] = (float)2.002; b[2][1] = (float)1.009; //multiply the matrices retcode = genMatrixMult(a,2,2,b,3,c); //display the result printf("%s", "Resultant Matrix Elements: \n\n"); for(i=0;i<2;++i){ for(j=0; j < 2; ++j){
printf("%s%d%s%d%s%f%s", "c[",i,"][",j,"] = ", c[i],"\n"); } } //display closing message and wait for <enter> before exiting printf("\nPress <Enter> to end"); scanf("%c", &ch); } // End Main /////////////////////////////// End splMMnm.c ///////////////////////