# Non-Square Matrix Multiplication

• 01-22-2012, 05:44 PM
j_arif123
Non-Square Matrix Multiplication
I titled this new thread as you see above because this kind of problems train us to handle the arrays effectively. I think, Giving solutions to these problems definitely feast our knowledge. As a beginger, its one of the interesting topic to begin with.
• 01-22-2012, 05:49 PM
j_arif123
Re: Non-Square Matrix Multiplication
For example , Lets take two matrices A(3,4) and B(4,2) . if we solve this , the resultant matrix will be R(3,2). This problem comes under Arrays Exercise . we use two dimenional
arrays to create a matrix.

Code:

```/* Exercise 5.14 Write a program to find the product of two matrices A(3,4) and B(4,2) page : 71 */ class Matrix        {         public static void main(String args[]) {         int i,j,k;         int r[][] = new int[3][2];                 int a[][] = {                                 {1,2,3,4},                                 {5,6,7,8},                                 {9,1,2,3}                                 };                 int b[][] ={                                 {1,2},                                 {3,4},                                 {5,6},                                 {7,8}                                 };                 // In this case , i dont know to handle these loops.                 for(i=0;i<2;i++)        {                 for(j=0;j<3;j++)        {                         for(k=0;k<4;i++)        {                                 r[j][i] += ( a[j][k] * b[k][i]);                         }                 }                 }                 for(i=0;i<3;i++)        {                 for(j=0;j<2;j++)        {                         System.out.println(r[i][j]+"\t");                 }                 System.out.print("\n");                 }         } }```
i could not solve it . Thanks in advance.
• 01-22-2012, 05:54 PM
Fubarable
Re: Non-Square Matrix Multiplication
Your current question is unanswerable since you don't tell us enough. You need to show us your attempt and then ask a specific question.
• 01-22-2012, 06:31 PM
Fubarable
Re: Non-Square Matrix Multiplication
Quote:

Originally Posted by j_arif123
I titled this new thread as you see above because this kind of problems train us to handle the arrays effectively. I think, Giving solutions to these problems definitely feast our knowledge. As a beginger, its one of the interesting topic to begin with.

Regarding your edited original post: no one here is interested in "giving a solution" since this will cheat you out of a valuable learning exercise, but on the other hand we will be more than happy to try to explain any points of confusion or help fix any errors in your code. But again, first you will need to ask a specific question and/or show us your code and your errors.
• 01-22-2012, 07:32 PM
JosAH
Re: Non-Square Matrix Multiplication
Matrix multiplication is taking the dot product of a row of matrix A and a column of matrix B (for each element of the product matrix). Also, two dimensional arrays in Java are just one dimensional arrays with one dimensional arrays as their elements. These two notions should be enough to implement it all ...

kind regards,

Jos