banner



How To Find The Product Of A Matrix

Plan to detect the product of two matrices

Explanation

In this programme, we need to multiply two matrices and print the resulting matrix.

Production of ii matrices

The production of two matrices tin can exist computed by multiplying elements of the commencement row of the offset matrix with the first column of the 2nd matrix then, add together all the product of elements. Continue this process until each row of the first matrix is multiplied with each column of the second matrix.

Program to find the product of two matrices

Consider higher up instance, outset element in resulting matrix prod[0,0] can be computed by multiplying outset row of get-go matrix i.eastward. (1, three, 2) with first column of 2nd matrix i.e. (2, 1, 1) and finally sum all the product of elements i.e. (1*two) + (3*ane) + (2*i) = seven. Similarly, second entry prod[0,i] can exist computed by multiplying the first row of the first matrix with the 2nd column of the 2nd matrix and sum all the production.

Two matrices can be multiplied if and just if they satisfy the following condition:

the number of columns present in the first matrix should exist equal to the number of rows present in the second matrix.

Suppose dimension of matrix A is p � q and matrix B is q � r, then the dimension of resulting matrix volition be p � r. Matrix multiplication can exist represented as

Algorithm

  1. Declare and initialize two two-dimensional arrays a and b.
  2. Calculate the number of rows and columns nowadays in the array a and shop it in variables row1 and col1 respectively.
  3. Calculate the number of rows and columns present in the array b and shop information technology in variables row2 and col2 respectively.
  4. Check if col1 is equal to row2. For ii matrices to be multiplied, the number of column in the kickoff matrix must be equal to the number of rows in the 2d matrix.
  5. If col1 is non equal to row2, brandish the message "Matrices cannot be multiplied."
  6. If they are equal, loop through the arrays a and b past multiplying elements of the starting time row of the first matrix with the first cavalcade of the second matrix and add together all the product of elements.
    eastward.g prod11 = a11 x b11 + a11 x b21 + a11 ten b31
  7. Repeat the previous step till all the rows of the start matrix is multiplied with all the columns of the 2nd matrix.
  8. Display the elements of array prod.

Solution

Python

Output:

Product of ii matrices:  7 7 6  eight 6 5  6 7 5          

C

Output:

Production of two matrices:  7 7 6  8 half dozen five  half dozen 7 v          

JAVA

Output:

Product of two matrices:  seven 7 6  8 6 v  6 vii v          

C#

Output:

Product of two matrices:  7 7 6  8 6 five  6 7 5          

PHP

Output:

Production of ii matrices:  7 7 half-dozen  8 half dozen 5  6 7 v          

Adjacent Topic #

Source: https://www.javatpoint.com/program-to-find-the-product-of-two-matrices#:~:text=The%20product%20of%20two%20matrices%20can%20be%20computed%20by%20multiplying,column%20of%20the%20second%20matrix.

Posted by: wigginscolusay.blogspot.com

0 Response to "How To Find The Product Of A Matrix"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel