Matrix Multiplication

 Matrix Multiplication


First be Know that What is matrix  A set of mn number (real or imaginary) arranged in the form of rectangular array of m rows and n columns is called m x n matrix  (to be read as ‘m by n’ matrix).


Matrix Multiplication


Let us first define the product of a row matrix and a column matrix.

Let  A= [a1, a2,  a3 …….. an] be a row matrix and  B =    b1         be a column matrix. Then , we define                                                                  b2 …                                                                                                                                      bn                                                                            A*B = a1b1 + a2b2 + a3b3 + …………….. + anbn.

Definition : Two matrices A and B are conformable for the product AB if the number of column in A (pre-multiplier) is same as the number of row in B(post-multipier).



On other word Column of matrix A is equal to Row of matrix B When result is matrix Row of matrix A and column of matrix B.



 



= 1*3 + 2*4 + 3*5 and similarly others. than the multiplication of the matrix is order(3 x 2) .

 



Program of Matrix Multiplication shown below :
// program for multiplication of two matrices.
#include<stdio.h>
#include<conio.h>
#define ROW1 3
#define COL1 3
#define ROW2 COL1
#define COL2 2
int main()
{
    int A[ROW1][COL1],B[ROW2][COL2],C[ROW1][COL2];
    int x,y,z;
    printf("Enter matrix A(%dx%d) Row-wise:\n",ROW1,COL1);
    for(x=0;x<ROW1;x++)
    {
        for(y=0;y<COL1;y++)
        {
            scanf("%d",&A[x][y]);
        }
    }
    printf("Enter matrix B(%dx%d) Row-wise:\n",ROW2,COL2);
    for(x=0;x<ROW2;x++)
    {
        for(y=0;y<COL2;y++)
        {
            scanf("%d",&B[x][y]);
        }
    }
    // Multiplication.
    for(x=0;x<ROW1;x++)
    {
        for(y=0;y<COL2;y++)
        {
            C[x][y]=0;
            for(z=0;z<COL1;z++)
            {
                C[x][y]+=A[x][z]*B[z][y]; //matrix multiply and add;
            }
        }
    }
    printf("multiplication of matrix A and  B is \n");
    for(x=0;x<ROW1;x++)
    {
        for(y=0;y<COL2;y++)
        {
            printf("%d\t",C[x][y]);
        }
        printf("\n");
    }
    return 0;
}
Output :
Enter matrix A(3x3) Row-wise: 1 2 3 4 5 6 7 8 9 Enter matrix B(3x2) Row-wise: 3 2 4 5 5 6yo multiplication of matrix A and B is 26 30 62 69 98 108
Thank you

 

 

Comments

Popular posts from this blog

5 d.) program to print this :