 Inverse matrices.
 Calculate matrix determinant.
 Set a row or a column of the matrix to a certain value.
 Calculate performance (time and memory taken by each algorithm).

## All 8 Replies

TRY THIS CODE THIS WILL HELP YOU TO FIND DETERMINANT COFACTOR ADJOINT AND INVERSE OF A MATRIX

``````#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<iomanip.h>
float A[3][3],B[3][3];
int i,j,k,l,m,n,e,f,g,h;
float det=0;
void main()
{
clrscr();
cout<<"Enter the 3x3 matrix :\n";
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>A[i][j];
//TO FIND COFACTOR AND DETERMINANT
for(i=0,k=1,m=2,e=-1,g=2;i<3;i++,e++,g--,k-=g,m-=e)
{
for(j=0,l=1,n=2,f=-1,h=2;j<3;j++,f++,h--,l-=h,n-=f)
{
B[i][j]=pow(-1,(i+j))*((A[k][l]*A[m][n])-(A[m][l]*A[k][n]));
if(i==0)
{
det+=A[i][j]*B[i][j];
}
}
}

cout<<"The determinant of the matrix is "<<det;

cout<<"\nCofactor of the matrix is :\n";
for(i=0;i<3;i++)
{
cout<<"\n";
for(j=0;j<3;j++)
cout<<setw(7)<<setprecision(3)<<B[i][j]<<"\t";
}
for(i=0;i<3;i++)
for(j=0;j<3;j++)
A[i][j]=B[j][i];

cout<<"\nAdjoint of the matrix is :\n";

for(i=0;i<3;i++)
{
cout<<"\n";
for(j=0;j<3;j++)
cout<<setw(7)<<setprecision(3)<<A[i][j]<<"\t";

}

//TO FIND INVERSE
for(i=0;i<=2;i++)
{
for(j=0;j<3;j++)
A[i][j]*=(1/det);
}
cout<<"\nInverse of the matrix is :\n";
for(i=0;i<3;i++)
{
cout<<"\n";
for(j=0;j<3;j++)
{
cout<<setw(7)<<setprecision(3)<<A[i][j]<<"\t";
}
}
getch();
}
``````
commented: I hope you get a passing grade for his/her homework -3

It is better in future to not give full answers to guestion (even I undestand not all points listed are implemented in posted code). It is also difficult to do performance to last point if she does not code it herself and the code is not really hers.

TRY THIS CODE THIS WILL HELP YOU TO FIND DETERMINANT COFACTOR ADJOINT AND INVERSE OF A MATRIX

``````    #include<iostream.h>
#include<conio.h>
#include<math.h>
#include<iomanip.h>
float A[3][3],B[3][3];
int i,j,k,l,m,n,e,f,g,h;
float det=0;
void main()
{
clrscr();
cout<<"Enter the 3x3 matrix :\n";
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>A[i][j];
//TO FIND COFACTOR AND DETERMINANT
for(i=0,k=1,m=2,e=-1,g=2;i<3;i++,e++,g--,k-=g,m-=e)
{
for(j=0,l=1,n=2,f=-1,h=2;j<3;j++,f++,h--,l-=h,n-=f)
{
B[i][j]=pow(-1,(i+j))*((A[k][l]*A[m][n])-(A[m][l]*A[k][n]));
if(i==0)
{
det+=A[i][j]*B[i][j];
}
}
}
cout<<"The determinant of the matrix is "<<det;
cout<<"\nCofactor of the matrix is :\n";
for(i=0;i<3;i++)
{
cout<<"\n";
for(j=0;j<3;j++)
cout<<setw(7)<<setprecision(3)<<B[i][j]<<"\t";
}
for(i=0;i<3;i++)
for(j=0;j<3;j++)
A[i][j]=B[j][i];
cout<<"\nAdjoint of the matrix is :\n";
for(i=0;i<3;i++)
{
cout<<"\n";
for(j=0;j<3;j++)
cout<<setw(7)<<setprecision(3)<<A[i][j]<<"\t";
}
//TO FIND INVERSE
for(i=0;i<=2;i++)
{
for(j=0;j<3;j++)
A[i][j]*=(1/det);
}
cout<<"\nInverse of the matrix is :\n";
for(i=0;i<3;i++)
{
cout<<"\n";
for(j=0;j<3;j++)
{
cout<<setw(7)<<setprecision(3)<<A[i][j]<<"\t";
}
}
getch();
}
``````

thank you all so much :)

"nitinmbhanu" has given you some code for a 3x3 matrix--assuming it is correct. However, I don't know if it will do you much good for a matrix of another size.

To set a row or a column of the matrix to a certain value should be easy enough, just use the assignment statement for the appropriate value.

To calculate the performance (time and memory) of the algorithm, is a little more difficult. One way to test the performance is to time program execution.

Have you done software timing yet?

the above code works well with 3x3 matrix as "DavidB" says and it wont do much good for a matrix of another size you try to code something yourself and only then you're gonna improve

the problem that i'm new in that field of c++ programming and there's alot of things i have to learn so can any one
help me but in simple way make me to understand