/*************************************************************************** |FILENAME MatrixMul.txt| Matrix Multiplication Logic ------------------- begin : |DATE 23/10/2003| copyright : (C) |YEAR 2003| by |CO-AUTHOR K. Manigandan| email : |EMAIL manik762002@yahoo.com| ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ /* ********************************************************************** */ // #include "/usr/include/c++/3.2.2/backward/alloc.h" #include char ** cMatMul(char **cMat1, int row1, int col1, char **cMat2, int row2, int col2) { char ** result = 0; char tempvalue = 0; int count1 = 0, count2 = 0, count3 = 0; if(col1 != row2) { // return result; } result = (char **)malloc(sizeof(char)*row1*col2); for(count1 = 0; count1 < row1; count1++) { for(count2 = 0; count2 < col1; count2++) { result[count1][count2] = tempvalue; for(count3 = 0; count3 < col2; count3++) { tempvalue = cMat1[count1][count3] * cMat2[count3][count2]; } } } return result; } int ** iMatMul(int **iMat1, int row1, int col1, int **iMat2, int row2, int col2) { int ** result = 0; int tempvalue = 0; int count1 = 0, count2 = 0, count3 = 0; if(col1 != row2) { return result; } result = (int **)malloc(sizeof(int)*row1*col2); for(count1 = 0; count1 < row1; count1++) { for(count2 = 0; count2 < col1; count2++) { result[count1][count2] = tempvalue; for(count3 = 0; count3 < col2; count3++) { tempvalue = iMat1[count1][count3] * iMat2[count3][count2]; } } } return result; } long ** lMatMul(long **lMat1, int row1, int col1, long **lMat2, int row2, int col2) { long ** result = 0; long tempvalue = 0; int count1 = 0, count2 = 0, count3 = 0; if(col1 != row2) { return result; } result = (long **)malloc(sizeof(long)*row1*col2); for(count1 = 0; count1 < row1; count1++) { for(count2 = 0; count2 < col1; count2++) { result[count1][count2] = tempvalue; for(count3 = 0; count3 < col2; count3++) { tempvalue = lMat1[count1][count3] * lMat2[count3][count2]; } } } return result; } float ** fMatMul(float **fMat1, int row1, int col1, float **fMat2, int row2, int col2) { float ** result = 0; float tempvalue = 0; int count1 = 0, count2 = 0, count3 = 0; if(col1 != row2) { return result; } result = (float **)malloc(sizeof(float)*row1*col2); for(count1 = 0; count1 < row1; count1++) { for(count2 = 0; count2 < col1; count2++) { result[count1][count2] = tempvalue; for(count3 = 0; count3 < col2; count3++) { tempvalue = fMat1[count1][count3] * fMat2[count3][count2]; } } } return result; } double ** dMatMul(double **dMat1, int row1, int col1, double **dMat2, int row2, int col2) { double ** result = 0; double tempvalue = 0; int count1 = 0, count2 = 0, count3 = 0; if(col1 != row2) { return result; } result = (double **)malloc(sizeof(double)*row1*col2); for(count1 = 0; count1 < row1; count1++) { for(count2 = 0; count2 < col1; count2++) { result[count1][count2] = tempvalue; for(count3 = 0; count3 < col2; count3++) { tempvalue = dMat1[count1][count3] * dMat2[count3][count2]; } } } return result; } long double ** ldMatMul(long double **ldMat1, int row1, int col1, long double **ldMat2, int row2, int col2) { long double ** result = 0; long double tempvalue = 0; int count1 = 0, count2 = 0, count3 = 0; if(col1 != row2) { return result; } result = (long double **)malloc(sizeof(long double)*row1*col2); for(count1 = 0; count1 < row1; count1++) { for(count2 = 0; count2 < col1; count2++) { result[count1][count2] = tempvalue; for(count3 = 0; count3 < col2; count3++) { tempvalue = ldMat1[count1][count3] * ldMat2[count3][count2]; } } } return result; } /* ****************************************************************************** */