I need to calculate the Inverse of A matrix.

An nxn matrix using different row operations:

Row Interchange: Row i is interchanged with Row j in matrix A. We write Ri ↔ Rj .

Row Scaling: Row i in matrix A is multiplied by a nonzero scaling factor c. We write

Ri ← cRi.

Row Addition: Row i in matrix A is replaced by the sum of Row i and a multiple m of

some row Row j. We write Ri ← Ri + mRj .

I need help setting up the algorithm..

So i make a matrix B the Identity Matrix

And i have to make A into the identity matrix using various row operations.

and whatever i do to A i have to do to B to get the inverse

So far I have :

Code:

#include<stdio.h>
void printMatrix (char name, double **matrix, int n)
{
printf("%c =\n", name);
int i,j;
for (i=0; i<n; i++)
{
for (j=0; j<n; j++)
{
if (matrix[i][j] == -0.0)
matrix[i][j] = 0.0;
printf(" %11.4e", matrix[i][j]);
}
printf("\n");
}
return;
}
int main()
{
int dimension;
printf("Enter the dimension of square matrix: \n");
scanf("%d",&dimension);
printf("Enter the %d entries of the matrix:", dimension*dimension);
scanf("%d %d", &dimension, &dimension);
// allocate the first dimension (rows)
int **matrix = (int **)malloc(dimension*sizeof(int *));
// allocate the second dimension (columns)
int i;
for (i=0; i<dimension; i++)
{
matrix[i] = (int *)malloc(dimension*sizeof(int));
}
int k,l;
for (k=0; k<M; k++)
{
for (l=0; l<N; l++)
{
scanf("%lf",&table[k][l]);
}
}
//Set up the identity Matrix
int **matrixB = (int **)malloc(dimension*sizeof(int *));
int j;
for (j=0; j<dimension; j++)
{
matrixB[i] = (int *)malloc(dimension*sizeof(int));
}
//Make B the identity Matirix.
int m,n;
for(m=0;m<=dimension;m++)
{
for(n=0;n<=dimension;n++)
{
if(m==n)
matrixB[m][m]=1;
else
matrixB[m][n]=0;
}
}
}