Question
Please solve in java and comment Problem Statement: Your assignment to design and Implement an Algorithm is Java to perform the following. . Addition and
Please solve in java and comment
Problem Statement:
Your assignment to design and Implement an Algorithm is Java to perform the following. . Addition and Multiplication of the arrays.. Below is the statement multiplying 2 matrices, As for Matrix Addition, you can come up with the algorithm.
Multiplication of two matrices is little complicated as compared to the addition of the two matrices. One of the basic condition for the multiplication of two matrices is number of columns of the first matrix equal to the number of rows of second matrix. This is the main condition for the multiplication of two matrices. 1. Input: We enter the number of rows, columns of two matrices. Later we enter the elements of the two matrices. 2. Explanation: while multiplying two matrices, we need to multiply the rows, columns. To get the element of the first row, first column element of the resultant matrixwe need to multiply the corresponding first row elements of first matrix with first column elements of second matrix and then add them. In the same way if we need to get the nth row, ith column..then we need to multiply the corresponding nth row elements of the first matrix with ith column of the second matrix and then add them.
From the above picture we can explain that we got the first row, first column element as 1*5+7*2=19.In the same way first row, second column element as 1*6+2*8=22.In the same way we can get the value of the element we need.
3.Output: We need to display the resultant matrix of multiplication. From the above explanation we shall write the code for multiplication.
So, Lets say we have two matrices Matrix A with m rows and n columns and Matrix B with n rows and p columns. Lets say we have to multiple a 23 matrix with a 32 matrix. Here is how we need to perform multiplication.
- The element in the first row first column of matrix A should be multiplied with the element in the first row first column of matrix B. The element in the first row second column of matrix A should be multiplied with the element in the second row first column of matrix B. Similarly the element in the first row third column of matrix A should be multiplied with the element in the third row first column of matrix B. The result of all these multiplication should be added together to get the first element of the resultant matrix.
- Similar step has to be followed by taking the elements in first row of matrix A and elements of second column in matrix B.
- Continue the above steps for second row of matrix A with first column of matrix B and second row of matrix A with second column of matrix B.
- The resultant matrix will be a 2*2 matrix.
Here is a pictorial representation of multiplying a 2*3 matrix with 3*2 matrix
Here are some of the points to be noted about matrix multiplication, as stated above.
- In order to multiply two matrices, the number of columns in the first matrix should be equal to the number of rows in the second matrix. Otherwise matrix multiplication cannot be done.
- The resultant of multiplication of m*n matrix with n*p matrix will be a m*p matrix.
- Matrix multiplication is not cumulative. It means, Matrix A x B Matrix B x A.
This project is listed on Page 224, Chapter 6 , Arrays , of the textbook.
B= 19 22 2 43 50 2 23 34 AB BA 123x90 45 6 58 17 + 29 + 311-58 58 64 1 2 3 4 56 x9 10 11 12 18 + 210+312 64 123 x 45 6 9 10 11 12 58 64 139 4x7 + 5x3 + 6x11 = 139 12 3x 456 x 9 10 11 12 58 644x8 +5x106x12 154 139 154Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started