Results 1 to 5 of 5
  1. #1
    j_arif123 is offline Member
    Join Date
    Jan 2012
    Location
    India
    Posts
    34
    Rep Power
    0

    Default 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

  2. #2
    j_arif123 is offline Member
    Join Date
    Jan 2012
    Location
    India
    Posts
    34
    Rep Power
    0

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

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

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

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Non-Square Matrix Multiplication

    Quote Originally Posted by j_arif123 View Post
    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.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,386
    Blog Entries
    7
    Rep Power
    20

    Default 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
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. int array multiplication
    By sternhagenr in forum New To Java
    Replies: 10
    Last Post: 08-20-2011, 01:41 AM
  2. need help with multiplication
    By dakid2 in forum New To Java
    Replies: 10
    Last Post: 03-08-2011, 03:41 AM
  3. Implement a multi-threaded matrix multiplication program.
    By redasu in forum Threads and Synchronization
    Replies: 0
    Last Post: 11-17-2010, 09:00 AM
  4. Multiplication table
    By rjones215 in forum New To Java
    Replies: 3
    Last Post: 10-19-2009, 04:34 PM
  5. Help with Multiplication
    By phil028 in forum New To Java
    Replies: 1
    Last Post: 12-06-2007, 07:39 PM

Posting Permissions

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