# includeint i, j; void display( int, int, float mat[10][10],float mat1[10][10]); void input( int, int, float mat[10][10],float mat1[10][10]); Inverse_Mat(int , int, float mat[10][10],float mat1[10][10]); void swap(int, int, int, float mat[10][10],float mat1[10][10]); /* This function exchange two rows of a matrix */ void swap( int row1,int row2, int col, float mat[10][10],float mat1[10][10]) { for( i = 0; i < col; i++) { float temp = mat[row1][i]; mat[row1][i] = mat[row2][i]; mat[row2][i] = temp; temp = mat1[row1][i]; mat1[row1][i] = mat1[row2][i]; mat1[row2][i] = temp; } } /* This function find inverse of matrix */ int Inverse_Mat(int row1, int col1, float mat[10][10],float mat1[10][10]) { int singular = 0; int r, c; for(r = 0;( r < row1)&& !singular; r++) { if( mat[r][r] ) /* Diagonal element is not zero */ for(c = 0; c < col1; c++) if( c == r) { /* Make all the elements above and below the current principal diagonal element zero */ float ratio = mat[r][r]; for( i = 0; i < col1; i++) { mat[r][i] /= ratio ; mat1[r][i] /= ratio; } } else { float ratio = mat[c][r] / mat[r][r]; for( i = 0; i < col1; i++) { mat[c][i] -= ratio * mat[r][i]; mat1[c][i] -= ratio * mat1[r][i]; } } else { /* If principal diagonal element is zero */ singular = 1; for(c = (r+1); (c < col1) && singular; ++c) if(mat[c][r]) { singular = 0; /* Find non zero elements in the same column */ swap(r,c,col1, mat, mat1); --r; } } } return(!singular); } /* To print output this is used */ void display( int row, int col, float mat[10][10],float mat1[10][10]) { printf("\n"); /* Output of inverse Matrix */ for( i = 0; i < row; i++) { for( j = 0; j < col; j++) { printf(" %f", mat1[i][j]); } printf("\n"); } } /* input function */ void input( int row, int col, float mat[10][10],float mat1[10][10]) { for( i = 0 ; i< row; i++) { for( j = 0 ; j
C Program to Find The Inverse of a Matrix
Next Article to Read
Among many other career blogs, Fun-The-Mentals is a different blog to help students achieve their goals.. This blog is maintained by Debashish and group. The blog is intended to bring decent and genuine information to the students of colleges and universities to help their preparation for job in the competitive world.
Add on Facebook
?
0 comments:
Post a Comment