Matrix Multiplication Program :
To multiply two matrices we need to first check
whether the two matrices can be multiplied or not. For that compare the first
matrix column with the rows of second matrix, if they are equal than only the
two matrices can be multiplied with each other.
For example :
Let the first matrix be of the order 3X3 and second
matrix be of the order of 3X2. Since both the no. of columns in first matrix
and no. of rows in second matrix are equal i.e. 3, the two matrices can be
multiplied with each other and the resultant matrix will be of the order 3X2
(rows in first matrix and columns in second matrix).
In general,
M(ixj) * M(jxk) = M(ixk)
To multiply the two matrices we need to multiply the
rows of first matrix to the columns of second matrix as shown below in the
diagram.
Now let’s consider the program of matrix
multiplication in which the two matrices are multiplied with the use of three
nested loops.
import java.util.Scanner;
class MatrixMulDemo
{
public static void main(String[] args)
{
//make a scanner for rows and columns
Scanner scan = new Scanner(System.in);
System.out.println("Enter the number of rows for first matrix");
//store rows in a variable
int rowsFirst = scan.nextInt();
System.out.println("Enter the number of columns for first matrix / rows of
second matrix (they must be same for matrix multiplication");
//store columns in a variable
int colFirstRowSec = scan.nextInt();
System.out.println("Enter the columns for second matrix");
//store columns of second matrix in a variable
int colSec = scan.nextInt();
//make two dimensional arrays for storing the matrices elements
int[][] first = new int[rowsFirst][colFirstRowSec];
int[][] second = new int[colFirstRowSec][colSec];
System.out.println("Enter the values of first matrix");
for(int i=0; i<first.length; i++)
{
for(int j=0; j<first[0].length; j++)
{
first[i][j] = scan.nextInt();
}
}
System.out.println("Enter the values of second matrix");
for(int i=0; i<second.length; i++)
{
for(int j=0; j<second[0].length; j++)
{
second[i][j] = scan.nextInt();
}
}
//define the third resultant matrix
int result[][] = new int[rowsFirst][colSec];
//multiply the two matrices using three nested loops
for(int i=0; i<rowsFirst; i++)
{
for(int j=0; j<colSec; j++)
{
for(int k=0; k<colFirstRowSec; k++)
{
result[i][j] = result[i][j] + first[i][k] * second
[k][j];
}
}
}
//print all the elements of result matrix
System.out.println("Product of two matrices ");
for(int i=0; i<result.length; i++)
{
for(int j=0; j<result[0].length; j++)
{
System.out.print(result[i][j] + " ");
}
//for line gap
System.out.println();
}
}
}
Thanks for sharing these niche piece of coding to our knowledge. Here, I had a solution for my inconclusive problems & it’s really helps me a lot keep updates…JAVA Course in Chennai
ReplyDeletethank you for your bolg with unique content.this is one of the recommanded blog.we appriciate your efforts.
ReplyDeleteJAVA Adavanced Online training
JAVA Adavanced Online training in hyderabad
wow it is very simple to learn. Thank you for sharing.| CCNA Training in Chennai
ReplyDeleter programming Training in Chennai | Selenium training in chennai
i like it.| SAS Training in Chennai |
ReplyDeleteDot Net Training in Chennai
Thank you so much for sharing. it’s useful for me...| Dot Net Training in IT Field
ReplyDeleteDot Net Training in OMR
After completing my basic core java knowldege, I have continued with this site. However, you should keep programming so simple for beginner as Java Online Tutorial has.
ReplyDeleteThank you for sharing such conceptual blog.
ReplyDeleteFind more details on Java Training
Java program is having expanding number of Job opportunities
ReplyDeleteFind best Java training institute in Delhi
java summer training
ReplyDelete
ReplyDeleteYour new valuable key points imply much a person like me and extremely more to my office workers. With thanks.
UNIX Shell scripting training in chennai
ORACLE apps finance training in chennai
Informatica Online Training
Thanks for providing solution.
ReplyDeleteBEST JAVA TRAINING IN DELHI
CIIT Noida provides Best MCA Courses in Noida based on the current
ReplyDeleteIT industry standards that help students to get high paying jobs in Top MNCs. CIIT provides Best MCA Training in Noida, Greater Noida, and Ghaziabad.
CIIT is one of the trusted MCA training institutes in Noida providing practical knowledge and 100% job assistance with basic as well as advanced
level MCA subjects. CIITN is the best MCA college in Noida, greater noida, ghaziabad, delhi, gurgaon regoin.
At CIIT MCA classes in Noida is conducted by subject experts corporate professionals with 9+ years of experience in managing real-time and live
projects. Sofracle Nano Specialized MCA classes Noida is the perfect blend of academic learning and practical sessions to provide maximum exposure to
students that transform an average student into a corporate professional whom companies prefer to hire.
Best MCA College in Noida
Java training in Noida and Java training in Delhi delivered by CIITN.we tend to gives it making prepared in lightweight of corporates standards that helps understudies to be prepare for endeavors. CIITN offers best Java training in Noida, CIITN is one among the most straightforward result arranged Java training establishment in Noida, offers best for all purposes and capacities, test data in Java training in Noida. CIITN Java training is coordinated by 15+ years of inclusion in supervising steady ventures. CIITN Noida, is giving basic and impelled level of Java training with live tasks with 100% job oriented plan encourage with top MNC.
ReplyDeleteJava Training in Noida
best java training in noida
Best M Tech Colleges in Noida
ReplyDeleteBest M Tech Colleges in Delhi
Best M Tech Colleges in Gurgaon
Best M Tech Colleges in UP
Best M Tech Colleges in India
Best M Tech Colleges in Hyderabad
Best M Tech Colleges in Bangalore
Best M Tech Colleges in Chennai
Those guidelines additionally worked to become a good way to recognize that other people online have the identical fervor like mine to grasp great deal more around this condition.
ReplyDeletepython Training in Bangalore | python Training in Bangalore
Great blog, thanks for sharing information with us!!!!
ReplyDeleteZenitech is best java training institute in Delhi. Our trainers realize what is required in Industry and help you learn and take a shot at International Standards.
Existing without the answers to the difficulties you’ve sorted out through this guide is a critical case, as well as the kind which could have badly affected my entire career if I had not discovered your website
ReplyDeleteAuthorized iphone service center in Chennai | iphone service center in chennai | Mobile service center in chennai | Authorized iphone service center in Chennai | iphone service center in chennai
The blog which you have shared is more useful for us.... Thanks for Sharing with us...
ReplyDeletePython Course in Coimbatore
Python Classes in Coimbatore
RPA Training in Coimbatore
Data Analytics Courses in Coimbatore
Web Designing Course in Coimbatore
Selenium Training in Coimbatore
Java Training in Coimbatore
Cloud Computing Courses in Coimbatore
Thanks for sharing such a great blog Keep posting..
ReplyDeleteJava Training in delhi
Java Training Course in delhi
I need to to thank you for your time due to this fantastic read!! I definitely enjoyed every bit of it and I have you bookmarked to see new information on your blog.
ReplyDeleteJava Training in Bangalore
thanks for sharing
ReplyDeletefull stack training in delhi
AI training course in Delhi
Power BI Institute in Delhi
tableau training in delhi
SASVBA
GMB
For more information
My brother suggested I might like this website. He was totally right. This post truly made my day. You can not imagine just how much time I had spent for this info! Thanks! imac computer berlin
ReplyDeleteAnnabelle loves to write and has been doing so for many years.Backlink Indexer My GPL Store Teckum-All about Knowledge
ReplyDeletenice article keep update. Thanks for such a great post
ReplyDelete"""Dream Teach Provides Best Teaching and Learning resources of geography in UK. It provides info on a geographical environmental quiz, journals that are helpful for Primary & Secondary Schools Teachers and Students.""
To know more about DreamTeach
Visit: geography learning resources!
ReplyDeleteI am really very happy to visit your blog. Directly I am found which I truly need. please visit our website for more information
Data visualization Service in USA
kadıköy beko klima servisi
ReplyDeletekartal alarko carrier klima servisi
ümraniye alarko carrier klima servisi
çekmeköy bosch klima servisi
ataşehir bosch klima servisi
çekmeköy arçelik klima servisi
maltepe mitsubishi klima servisi
pendik arçelik klima servisi
tuzla samsung klima servisi
The blog effectively explains the process of matrix multiplication and provides a clear understanding of the topic. It serves as a helpful guide for anyone looking to learn or refresh their knowledge on matrix multiplication. Keep up the good work!
ReplyDeleteTo know more about java program, I recommend Java Certification Course in Indore as a best place for learning.
Thank you for sharing such conceptual blog. So informative blog.
ReplyDeleteBest Data science Training in Kolkata
If you're eager to embark on a comprehensive journey into the world of Java Full Stack development, look no further than APTRON's Java Full Stack Course in Noida. This dynamic and industry-focused program is designed to equip you with the skills and knowledge necessary to excel in today's competitive tech landscape. Noida, with its burgeoning IT sector, provides an ideal backdrop for honing your Full Stack expertise.
ReplyDeleteGreat article.
ReplyDeletehttps://www.iteducationcentre.com/java-training-classes-in-pune.php