Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Gail Knight   on Jun 01 In Java Category.

  
Question Answered By: Allan Bailey   on Jun 01

this code do the stuff.
any length matrix  in 2 dimension


public static int[][] multiplicate(int[][] a, int[][] b)
{
// Matrix a has m rows, and n cols
// Matrix b has n rows, and p cols
int m = a.length;
int n = ((int[])a[0]).length;
int p = ((int[])b[0]).length;
int[][] result = new int[m][p];

for (int i = 0; i < m; i++)
{
for (int j = 0; j < p; j++)
{
int partial = 0;
for (int h = 0; h < n; h++)
{
partial += a[i][h] * b[h][j];
}
res[i][j] = partial;
}
}

return result;
}

Share: 

 

This Question has 1 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on matrix multiplication Or get search suggestion and latest updates.


Tagged: