multiplication static method
Return matrix multiplication of a
and b
Throw an exception
if dimension's condition not met
Implementation
static Matrix multiplication(Matrix a, Matrix b) {
if (a.m == b.n) {
var resultMatrix = Matrix.zero(n: a.n, m: b.m);
for (int i = 0; i < resultMatrix.n; i += 1) {
for (int j = 0; j < resultMatrix.m; j += 1) {
double sum = 0;
for (int k = 0; k < a.m; k += 1) {
sum += a[i][k] * b[k][j];
}
resultMatrix[i][j] = sum;
}
}
return resultMatrix;
} else {
throw Exception('Dimensions error: A.m != B.n |${a.m}) != ${b.n}|');
}
}