Not Yet Answered # matrix operation

nitinmbhanu -3 pyTony 888 nitinmbhanu -3 DavidB 44 nitinmbhanu -3 pyTony 888 Discussion Starter samar11 Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...

0

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";
}
//TO FIND ADJOINT
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();
}
```

0

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.

1

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";
}
//TO FIND ADJOINT
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();
}
```

0

"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?

0

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

0

Lik e allready mentioned in other threads check http://en.wikipedia.org/wiki/Gaussian_elimination

0

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

thanks again in advance

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.

This is the result of previous question answered :

code for the listbox - datagridview interaction

At the top of the code ...

the function that I created to find the ...