RUPAK SEARCH ENGINE

Custom Search

inverse matrix numerical method program in C

/*Inverse matrix*/
#include
#include
#define n 3
void main()
{
int i,j,k;
float a[n][n],b[n][n],ratio;
printf("Enter matrix elements of A:\n");
for(i=0;i {
for(j=0;j {
printf("a[%d][%d]=",i,j);
scanf("%f",&a[i][j]);
}
}
printf("Press Enter to find Inverse Matrix\n\n");
getch();
clrscr();
printf("You have entered the matrix elements of A:\n");
for(i=0;i {
for(j=0;j {
printf("%.1f\t",a[i][j]);
}
printf("\n");
}

for(i=0;i {
for(j=0;j {
if(i==j)
b[i][j]=1;
else
b[i][j]=0;
}
}
for(k=0;k {
for(i=0;i {
if(i==k)continue;
ratio=(a[i][k])/(a[k][k]);
for(j=0;j {
a[i][j]=a[i][j]-ratio*a[k][j];
b[i][j]=b[i][j]-ratio*b[k][j];
}
}
}
for(i=0;i {
for(j=0;j {
a[i][j]=a[i][j]/a[i][i];
b[i][j]=b[i][j]/a[i][i];
}
}
printf("Inverse matrix elements of A:\n");
for(i=0;i {
for(j=0;j {
printf("%.1f\t",b[i][j]);
}
printf("\n");
}
getch();
}
/*
OUTPUT:
Enter matrix elements of A:
a[0][0]=1
a[0][1]=3
a[0][2]=3
a[1][0]=1
a[1][1]=4
a[1][2]=3
a[2][0]=1
a[2][1]=3
a[2][2]=4
Press Enter to find Inverse Matrix (give Enter, clear screen)
You have entered the matrix elements of A:
1.0 3.0 3.0
1.0 4.0 3.0
1.0 3.0 4.0
Inverse matrix elements of A:
7.0 -3.0 -3.0
-1.0 1.0 0.0
-1.0 0.0 1.0
*/

No comments:

Post a Comment