Skip to content

Instantly share code, notes, and snippets.

@moomoohk
Forked from anonymous/gist:7760201
Last active December 30, 2015 02:08
Show Gist options
  • Save moomoohk/7760210 to your computer and use it in GitHub Desktop.
Save moomoohk/7760210 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