Inverse of matrix

Program to find inverse of nth order square matrix?(c++)

Questions by klvgopi

Showing Answers 1 - 3 of 3 Answers

void trans(float num[25][25],float fac[25][25],float r)

{
int i,j;
float b[25][25],inv[25][25],d;
for(i=0;i {
for(j=0;j {
b[i][j]=fac[j][i];
}
}

d=detrm(num,r);
inv[i][j]=0;
for(i=0;i {
for(j=0;j {
inv[i][j]=b[i][j]/d;
}
}

printf("
THE INVERSE OF THE MATRIX:
");
for(i=0;i {
for(j=0;j {
printf(" %f",inv[i][j]);
}
printf("
");
}
}

we need determinant to find the inverse
The program for determinant is
float detrm(float a[25][25],float k)
{
float s=1,det=0,b[25][25];
int i,j,m,n,c;
if(k==1)
{
return(a[0][0]);
}
else
{
det=0;
for(c=0;c {
m=0;
n=0;
for(i=0;i {
for(j=0;j {
b[i][j]=0;
if(i!=0&&j!=c)
{
b[m][n]=a[i][j];
if(n<(k-2))
n++;
else
{
n=0;
m++;
}
}
}
}
det=det+s*(a[0][c]*detrm(b,k-1));
s=-1*s;
}
}
return(det);
}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions