Skip to content

Instantly share code, notes, and snippets.

Created December 2, 2013 22:25
Show Gist options
  • Save anonymous/7760201 to your computer and use it in GitHub Desktop.
Save anonymous/7760201 to your computer and use it in GitHub Desktop.
public matrix mul(matrix B) {
// Return a new matrix which is the matrix product of this
// with B.
if((rows()!=B.rows()) || (cols()!=B.cols())) {
System.out.println("Error, cannot add since the 2 matrices do not have the same dimensions.");
System.exit(0);
}
matrix M = new matrix(rows(), cols());
for(int i = 1; i <= rows(); i++) {
for(int j = 1; j <= B.cols(); j++) {
for(int k = 0; k < cols(); k++) {
M.set(i,j, M.get(i,j) + get(i,k) * B.get(k,j));
}
}
}
return M;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment