answersLogoWhite

0


Best Answer

#include<stdio.h>

#include<math.h>

float detrm(float[][],float);

void cofact(float[][],float);

void trans(float[][],float[][],float);

main()

{

float a[25][25],k,d;

int i,j;

printf("ENTER THE ORDER OF THE MATRIX:\n");

scanf("%f",&k);

printf("ENTER THE ELEMENTS OF THE MATRIX:\n");

for(i=0;i<k;i++)

{

for(j=0;j<k;j++)

{

scanf("%f",&a[i][j]);

}

}

d=detrm(a,k);

printf("THE DETERMINANT IS=%f",d);

if(d==0)

printf("\nMATRIX IS NOT INVERSIBLE\n");

else

cofact(a,k);

}

/******************FUNCTION TO FIND THE DETERMINANT OF THE MATRIX************************/

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<k;c++)

{

m=0;

n=0;

for(i=0;i<k;i++)

{

for(j=0;j<k;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);

}

/*******************FUNCTION TO FIND COFACTOR*********************************/

void cofact(float num[25][25],float f)

{

float b[25][25],fac[25][25];

int p,q,m,n,i,j;

for(q=0;q<f;q++)

{

for(p=0;p<f;p++)

{

m=0;

n=0;

for(i=0;i<f;i++)

{

for(j=0;j<f;j++)

{

b[i][j]=0;

if(i!=q&&j!=p)

{

b[m][n]=num[i][j];

if(n<(f-2))

n++;

else

{

n=0;

m++;

}

}

}

}

fac[q][p]=pow(-1,q+p)*detrm(b,f-1);

}

}

trans(num,fac,f);

}

/*************FUNCTION TO FIND TRANSPOSE AND INVERSE OF A MATRIX**************************/

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<r;i++)

{

for(j=0;j<r;j++)

{

b[i][j]=fac[j][i];

}

}

d=detrm(num,r);

inv[i][j]=0;

for(i=0;i<r;i++)

{

for(j=0;j<r;j++)

{

inv[i][j]=b[i][j]/d;

}

}

printf("\nTHE INVERSE OF THE MATRIX:\n");

for(i=0;i<r;i++)

{

for(j=0;j<r;j++)

{

printf("\t%f",inv[i][j]);

}

printf("\n");

}

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago
  1. #include
  2. int main(){
  3. int a[3][3],i,j;
  4. float determinant=0;
  5. printf("Enter the 9 elements of matrix: ");
  6. for(i=0;i<3;i++)
  7. for(j=0;j<3;j++)
  8. scanf("%d",&a[i][j]);
  9. printf("\nThe matrix is\n");
  10. for(i=0;i<3;i++){
  11. printf("\n");
  12. for(j=0;j<3;j++)
  13. printf("%d\t",a[i][j]);
  14. }
  15. for(i=0;i<3;i++)
  16. determinant = determinant + (a[0][i]*(a[1][(i+1)%3]*a[2][(i+2)%3] - a[1][(i+2)%3]*a[2][(i+1)%3]));
  17. printf("\nInverse of matrix is: \n\n");
  18. for(i=0;i<3;i++){
  19. for(j=0;j<3;j++)
  20. printf("%.2f\t",((a[(i+1)%3][(j+1)%3] * a[(i+2)%3][(j+2)%3]) - (a[(i+1)%3][(j+2)%3]*a[(i+2)%3][(j+1)%3]))/ determinant);
  21. printf("\n");
  22. }
  23. return 0;
  24. }
This answer is:
User Avatar

User Avatar

Wiki User

12y ago

#include<stdio.h>

#include<math.h>

float detrm( float[][], float );

void cofact( float[][], float );

void trans( float[][], float[][], float );

main()

{

float a[ 25 ][ 25 ], k, d;

int i, j;

printf( "ENTER THE ORDER OF THE MATRIX:\n" );

scanf( "%f", &k );

printf( "ENTER THE ELEMENTS OF THE MATRIX:\n" );

for ( i = 0;i < k;i++ )

{

for ( j = 0;j < k;j++ )

{

scanf( "%f", &a[ i ][ j ] );

}

}

d = detrm( a, k );

printf( "THE DETERMINANT IS=%f", d );

if ( d 1 )

{

return ( a[ 0 ][ 0 ] );

}

else

{

det = 0;

for ( c = 0;c < k;c++ )

{

m = 0;

n = 0;

for ( i = 0;i < k;i++ )

{

for ( j = 0;j < k;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 );

}

/*******************FUNCTION TO FIND COFACTOR*********************************/

void cofact( float num[ 25 ][ 25 ], float f )

{

float b[ 25 ][ 25 ], fac[ 25 ][ 25 ];

int p, q, m, n, i, j;

for ( q = 0;q < f;q++ )

{

for ( p = 0;p < f;p++ )

{

m = 0;

n = 0;

for ( i = 0;i < f;i++ )

{

for ( j = 0;j < f;j++ )

{

b[ i ][ j ] = 0;

if ( i != q && j != p )

{

b[ m ][ n ] = num[ i ][ j ];

if ( n < ( f - 2 ) )

n++;

else

{

n = 0;

m++;

}

}

}

}

fac[ q ][ p ] = pow( -1, q + p ) * detrm( b, f - 1 );

}

}

trans( num, fac, f );

}

/*************FUNCTION TO FIND TRANSPOSE AND INVERSE OF A MATRIX**************************/

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 < r;i++ )

{

for ( j = 0;j < r;j++ )

{

b[ i ][ j ] = fac[ j ][ i ];

}

}

d = detrm( num, r );

inv[ i ][ j ] = 0;

for ( i = 0;i < r;i++ )

{

for ( j = 0;j < r;j++ )

{

inv[ i ][ j ] = b[ i ][ j ] / d;

}

}

printf( "\nTHE INVERSE OF THE MATRIX:\n" );

for ( i = 0;i < r;i++ )

{

for ( j = 0;j < r;j++ )

{

printf( "\t%f", inv[ i ][ j ] );

}

printf( "\n" );

}

}

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

Use the Eigen library to find the inverse of matrices. It is simpler and more efficient than trying to write your own. The only reason to write your own is when you have a better, more efficient method than those that already exist.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a c plus plus program for finding the inverse of a given matrix?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a c program to determine whether a matrix is singular or not?

A c program is also known as a computer program. A singular matrix has no inverse. An equation to determine this would be a/c=f. &lt;&lt;&gt;&gt; The determinant of a singular matix is zero.


Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 matrix?

Sp[[Q/Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 matrix|Answer]]ell chec[[Q/Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 matrix&amp;action=edit&amp;section=new|Answer it!]]k your answe[[Q/Discuss:Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 matrix|Disc]][[help/answering questions|guidelin]]Spell check your answeresussionr[[help/signing in|full benefits]] Save C[[Q/Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 matrix|Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 ]][[Q/Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 matrix&amp;action=edit&amp;section=new|Answering 'Write a 8085 microprocessor program to find A inverse and A transpose if A is a 3x3 matrix?']]matrix?ancel[[Q/How many animals are in West Texas|How many animals are in West Texas?]][[Q/How do you increase the number of four wheelers vehicles for servicing in a Service workshop|How do you increase the number of four wheelers vehicles for servicing in a]][[Q/How do you increase the number of four wheelers vehicles for servicing in a Service workshop|How do you increase the number of four wheelers vehicles for servicing in a Service workshop?]] Service workshop?[[Q/How do you increase the number of four wheelers vehicles for servicing in a Service workshop|How do you increase the number of four wheelers vehicles for servicing in a Service workshop?]]More Q&amp;A


Write a program to multiply 33 matrix.?

write a program to multily 3*3 matrix.


2x2 matrix multiplication program in 8085 processor?

how to write a program for matrix multiplication in microprocesspr


How can you write a program which proves that a multiple of a matrix and its determinant is an identity matrix?

Automated proofs are a complicated subject. If you are not an expert on the subject, all you can hope for is to write a program where you can input a sample matrix (or that randomly generates one), and verifies the proposition for this particular case. If the proposition is confirmed in several cases, this makes the proposition plausible, but is by no means a formal proof.Better try to prove it without writing any program.Note: it is not even true; it is the inverse of the matrix which gives identity when is multiplied with the original matrix.


How do you Write A program in c language for checking a diagonal matrix?

Write a program in c++ that take input in a integer matrix of size 4*4 and find out if the entered matrix is diagonal or not.


A c program to square matrix?

A C program to square matrix is a math problem. In the math problem you write down all the outer boundary values of matrix in a circle, then write down the inner value.


Write a c program to find eigenvalue of a matrix?

Yes, do write. That's what you always have to do when you have got a homework-program.


How do you write a java program to find the transpose of the matrix for the given elements?

You basically write a nested for loop (one for within another one), to copy the elements of the matrix to a new matrix.


How do you write a java program to find the ad joint of a matrix?

bgfygfrhjyuyhh


Write a program to print the sum of a sparse matrix?

This is a directive, not a question.


Write a C program to find sum of 3 matrices?

matrix