home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / elem-c.zip / M_MULTIP.C < prev    next >
C/C++ Source or Header  |  1985-05-18  |  4KB  |  30 lines

  1. static char *sccsid = "@(#)m_multiply.c    4/6/82 (U of Maryland, FLB)";
  2.  
  3. #include "mat.h"
  4.  
  5. struct matrix *
  6. m_multiply(mat1, mat2)
  7. register struct matrix *mat1, *mat2;
  8. {
  9. register struct matrix *result;
  10. register int row, col, ix;
  11. double sum;
  12.  
  13. if (mat1->m_cols != mat2->m_rows) {
  14.     printf("m_multiply: matrices not compatible.\n");
  15.     return(M_NULL);
  16.     }
  17.  
  18. m_create(result, mat1->m_rows, mat2->m_cols);
  19.  
  20. for (row = 0; row < mat1->m_rows; row++)
  21.     for (col = 0; col < mat2->m_cols; col++) {
  22.         sum = 0.0;
  23.         for (ix = 0; ix < mat1->m_cols; ix++)
  24.             sum += m_v(mat1, row, ix) * m_v(mat2, ix, col);
  25.         m_v(result, row, col) = sum;
  26.         }
  27.  
  28. return(result);
  29. }