1. Member Join Date
Jan 2012
Location
India
Posts
34
Rep Power
0

## 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.
Last edited by j_arif123; 01-22-2012 at 05:07 PM. Reason: To give enough description  Reply With Quote

2. Member Join Date
Jan 2012
Location
India
Posts
34
Rep Power
0

## 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.

Java 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;
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.
Last edited by j_arif123; 01-22-2012 at 06:47 PM. Reason: to present the code.  Reply With Quote

3. ## 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.  Reply With Quote

4. ## Re: Non-Square Matrix Multiplication 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.  Reply With Quote

5. ## 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  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•