Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Having problem in matrix multiplication....

  1. #1
    Junior Member
    Join Date
    Aug 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Having problem in matrix multiplication....

    Can anybody help me out how to write a program of multiplication of two matrix with taking input for rows and column through the Buffered Reader ie. by taking inputs of my own form keyboards ?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,108
    Thanks
    52
    Thanked 2,285 Times in 2,256 Posts

    Default Re: Having problem in matrix multiplication....

    how to write a program of multiplication of two matrix
    Define the algorithm for the "multiplication of two matrix".
    Given that we can help you write the java code.

  3. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Having problem in matrix multiplication....

    See: Matrix multiplication for how to multiply two matrices. Personally, I would implement the naive method because it's much easier, but if you want better performance for larger matrices, there's Strassen's method or Coppersmith–Winograd algorithm (only use these for large matrices, they're considerably slower for smaller ones).

    If you're unsure how to program in Java, I recommend reading: Leaerning the Java Language.

  4. #4
    Junior Member
    Join Date
    Aug 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Having problem in matrix multiplication....

    But i need the code that one can use his/her own input from keyboard for the rows and column. The data input part i can do it.

  5. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Having problem in matrix multiplication....

    Do you have to use a BufferedReader? If you can, use the Scanner object. It makes reading in data (especially numbers) much easier.

    If you must use a BufferedReader, what I would do is read in "words" (elements separated by spaces), then use Integer.parseInt() or Double.parseDouble() to get the data value from the string. Scanner has methods called nextInt() and nextDouble() which basically automate this process.

  6. #6
    Junior Member
    Join Date
    Mar 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Having problem in matrix multiplication....

    public class ArrayMultiplication
    {
    public static void main(String s[])
    {
    int rows1=Integer.parseInt(s[0]);
    int columns1=Integer.parseInt(s[1]);
    int rows2=Integer.parseInt(s[2]);
    int columns2=Integer.parseInt(s[3]);
    int array1[][]=new int[rows1][columns1];
    int array2[][]=new int[rows2][columns2];
    int array3[][]=new int[rows1][columns2];


    if(columns1==rows2)

    {
    int m=4;
    for(int i=0;i<rows1;i++)
    {
    for(int j=0;j<columns1;j++)
    {
    array1[i][j]= Integer.parseInt(s[m]);
    m=m+1;


    }

    }
    int l=4+(rows1*columns1);
    for(int i=0;i<rows2;i++)
    {
    for(int j=0;j<columns2;j++)
    {

    array2[i][j]=Integer.parseInt(s[l]);
    l=l+1;

    }

    }


    for(int i=0;i<rows1;i++)
    for(int k=0;k<columns2;k++)
    for(int j=0;j<rows2;j++)
    {
    array3[i][k]=array3[i][k]+(array1[i][j])*(array2[j][k]);
    }

    for(int i=0;i<rows1;i++)
    {
    System.out.println("");
    for(int j=0;j<columns2;j++)
    {
    System.out.print(array3[i][j]+"\t");
    }
    }


    }
    else
    {
    System.out.println("The arrays cannot be multiplied");

    }
    }
    }

Similar Threads

  1. Embedding images in a matrix.
    By Aims_ in forum Java Theory & Questions
    Replies: 1
    Last Post: September 11th, 2009, 02:37 PM
  2. Creating A Count Matrix In Java
    By statsman5 in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: July 14th, 2009, 04:40 PM