johnmcglone.com

a blog of things people probably won't care about

I think this matrix multiplication algorithm is simple and efficient

Tell me what you think. (* .c = columns, .r = rows)

public static JMMatrix multiply(JMMatrix A, JMMatrix B)
{
//if the matrices are not able to be multiplied, return null
if(A.c != B.r)
return null;
// the matrix to return
float[][] matrix = new float[A.r][B.c];
//n is the length of the vectors that make up matrix B
int n = B.matrix.length;
[...]

Matrix Multiplication algorithm

I’m trying to write a function that will take 2 matrices of any size, given they are able to be multiplied, and return the result of matrix1 * matrix2. My JMMatrix class works like a charm (just a 2d array!). However, my multiplication function is NOT working.
I’ve kept in mind the following:

Given Matrix [...]

TEST!