Matrix Multiplication in C
The Concept behind Matrix Multiplication
Two matrixes of order ( m x n ) and ( o x p ) can only be multiplied if ( n = p ). Other-wise matrix multiplication is not possible. So, the matrix-es must full-fill the condition before going forward. Following the multiplication pattern the syntax for matrix multiplication is as follows.
As ( n = p ), we consider the order of the matrix ( m x n ) and ( n x p ). So the generalized syntax of the matrix multiplication will be :
For [1st Matrix - A ]( m x n ) X ( n x p )[Second Matrix - B ] matrix :
Resultant Matrix - C ( m x p ) Sum - temporary varible to store iterations. for(i=0;i<m;i++) { for(j=0;j<p;j++) { sum=0; for(k=0;k<n;k++) { sum=sum+A[i][k]*B[k][j]; } C[i][j]=sum; } }
Matrix Multiplication program in C:
Comments
Post a Comment