To calculate the Inverse of a Matrix using Gauss Jordon Method
Program to calculate the Inverse of a Matrix using Gauss Jordon Method, a simple yet complete algorithm follows below.
Gauss Jordon Method can be employed to solve a system of linear equations having solutions. Unlink in Gauss Elimination method (in which triangular matrix is formed), in Gauss Jordon Method all off diagonal elements are eliminated producing a diagonal matrix. Finally, inverse of the matrix formed by system of equations is computed.
[A:I]?[I:A-1]
where
[A]= matrix to be solved for
[A-1]= required inverse matrix
[I]= identity matrix
/** To compute the inverse of matric [A] using Gauss Jordon Method
Simple but complete algorithm
1. start
2. n ie size of sq matrix
3.matrix reading
i= 1 to n
j= 1 to n
read a[i][j]
2.identity matrix
i= 1 to n
j= 1 to n
{
if(i==j)
b[i][j]=1
else
b[i][j]=0
}
3.elimination
k= 1 to n
{
i= 1 to n
{
if(i==k) goto LABEL;
pivot= a[i][k]/a[k][k]
j= 1 to n
{
a[i][j]= a[i][j]-pivot*a[k][j]
b[i][j]= b[i][j]-pivot*b[k][j]
}
LABEL
}
}
4.identity matrix
i= 1 to n
j= 1 to n
b[i][j]= b[i][j]/a[i][i]
5.display inverse matrix
i= 1 to n
j= 1 to n
cout "b["<<
*************************************/
#include
#include
#include
void main()
{
int n;
clrscr();
cout<<"INVERSE OF MATRIX BY GAUSS JORAN METHOD"<<
double i,j,k,pivot,a[10][10],b[10][10];
cout<<"Please,enter the size of Square matrix "<
cin>>n;
cout<<"The size of matrix is "<<<" X "<<
cout<<"Enter the elements of the matrix"<
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
cout<<"a"<<<<"= ";
cin>>a[i][j];
cout<
}
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(i==j)
{
b[i][j]=1;
}
else
{
b[i][j]=0;
}
}
}
for(k=1;k<=n;k++)
{
for(i=1;i<=n;i++)
{
if(i==k)
goto label;
pivot=a[i][k]/a[k][k];
for(j=1;j<=n;j++)
{
a[i][j]=a[i][j]-pivot*a[k][j];
b[i][j]=b[i][j]-pivot*b[k][j];
}
label:
}
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
b[i][j]=b[i][j]/a[i][i];
}
}
cout<<"The inverse of matrix is"<
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
cout<<<"b"<<<<"= "<<
}
}
getch();
}
To calculate the Inverse of a Matrix using Gauss Jordon Method in C++ Programming Language for Numerical Methods for Engineering Students
| < Prev | Next > |
|---|



