| 1 |
#include <stdio.h> |
| 2 |
#include "mat.h" |
| 3 |
#include "matrixdefs.h" |
| 4 |
#include "local_proto.h" |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
int m_mult(MATRIX *a, MATRIX *b, MATRIX *c) |
| 10 |
{ |
| 11 |
register int i, j, k, nr, nc, ncols; |
| 12 |
char message[256]; |
| 13 |
|
| 14 |
if (a->nrows == 0) |
| 15 |
return error("*: arg1 not defined\n"); |
| 16 |
else if (b->nrows == 0) |
| 17 |
return error("*: arg2 not defined\n"); |
| 18 |
|
| 19 |
|
| 20 |
if (a->ncols != b->nrows) { |
| 21 |
snprintf(message, sizeof(message), |
| 22 |
"*: matrices not conformable, %d x %d * %d x %d\n", a->nrows, |
| 23 |
a->ncols, b->nrows, b->ncols); |
| 24 |
fprintf(stderr, "%s", message); |
| 25 |
return error(message); |
| 26 |
} |
| 27 |
|
| 28 |
ncols = a->ncols; |
| 29 |
nr = a->nrows; |
| 30 |
nc = b->ncols; |
| 31 |
for (i = 0; i < nr; i++) |
| 32 |
for (j = 0; j < nc; j++) { |
| 33 |
c->x[i][j] = 0.0; |
| 34 |
for (k = 0; k < ncols; k++) |
| 35 |
c->x[i][j] += (a->x[i][k] * b->x[k][j]); |
| 36 |
} |
| 37 |
|
| 38 |
c->nrows = nr; |
| 39 |
c->ncols = nc; |
| 40 |
return 1; |
| 41 |
} |