Matrix multiplication algorithm

Authors Avatar

Creation and implementation of an algorithm that works the Matrix multiplication

            n-1

Cij = ∑aik * bkj 

           K=0

  1. Basic operations
  1. Comparison of number of rows of one matrix and number of columns of another to see if they are compatible
  2. Multiplication
  1. Work done

Running time = φ(n3)

  1. Algorithm

Input number of rows and columns for each of the matrix

{

If(columnsofA !=rowsofb)

Through invalid argument (“incompatible matrices”)

Input the two matrice

For(I=o;I<numbercolumnsA;++I)

      {

                for(j=0;j<numberofcolumnsB;++j)

                        {

sum=0;

for(k=0;k<numberofcolumnsA;++k)

        {

Join now!

                sum+=A[i][j]*B[j][k];

                C[i][j]=sum;

        }end for

                        }end for

        }end for

return result

}

(d)Algorithm implemented in C language

// maltidimension.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

#include<stdlib.h>

//#pragma hdrstop

//#pragma argsused

int main(int argc, char* argv[])

{

        int ncol,nrow,argnrow,argncol,i,j,k,p,sum;

        int a[20][20],b[20][20],c[20][20];

start: printf("enter the value of ncol");

scanf("%d",&ncol);

        printf("enter the value of nrow");

scanf("%d",&nrow);

printf("enter the value of argncol");

scanf("%d",&argncol);

printf("enter the value of argnrow");

scanf("%d",&argnrow);

if(ncol !=argnrow)

{

printf("matrices are incompatible");

 goto start;

}

printf("enter matrix A\n");

for(i=0;i<nrow;++i)

{

        for(j=0;j<ncol;++j)

        {

                scanf("%d",&p);

                a[i][j]=p;

        }

        printf("\n");

}

printf("enter matrix B\n");

for(j=0;j<argnrow;++j)

{

        for(k=0;k<argncol;++k)

        {

...

This is a preview of the whole essay