Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

Below is the method which I want it to return the product matrix. 

   public Matrix multiply(Matrix A) {

            ////code

   }

Since it’s multiplication on the right, I think I should do A.multiply(B) to return matrix AB, with B on the right. Can anyone tell me an easy algorithm to achieve this? 

1 Answer

0 votes
by (19.7k points)

If speed is not a concern for you, you can do the below O(n^3) implementation:

  for (int i=0; i<l; ++i)

    for (int j=0; j<n; ++j)

      for (int k=0; k<m; ++k)

        c[i][j] += a[i][k] * b[k][j]  

Interested in Java? Check out this Java Certification by Intellipaat. 

Related questions

0 votes
1 answer
asked Feb 9, 2021 in Python by laddulakshana (16.4k points)
0 votes
1 answer
asked Jun 3, 2020 in R Programming by ashely (50.2k points)
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...