Problem Description: Following is given a C++ Program that finds the inverse of
ID: 3583298 • Letter: P
Question
Problem Description: Following is given a C++ Program that finds the inverse of a 3*3 matrix using the Adjoint method given as follows Further details of this method you can find on the web page Matrix is represented by a two dimensional array in the program. And the matrix should be initialized by the random values each time you run the program. In the given program you will not change any function declarations or variable names or anything inside main. Just complete the function definitions. Instructions are written in the form of comments inside each function to explain what logic to implement. After reading carefully you can determine what is the input and output to each function and how the data is being exchanged between the main program and the functions. After completing the functions definitions your program should run and may produce the output like given below. For any further help and explanation contact your teacher.Explanation / Answer
#include<bits/stdc++.h>
using namespace std;
void inputMatrxi(float a[3][3])
{
int i,j;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
a[i][j]=rand()%100+1;
}
}
}
void display(float a[3][3])
{int i,j;
cout<<" The entered matrix is: ";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<a[i][j]<<" ";
}
cout<<" ";
}
}
void Inverse(float a[3][3])
{
int i,j;
float determinant=0;
for(i=0;i<3;i++)
{
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]));
}
if(determinant==0)
{
cout<<"Inverse does not exist (Determinant=0). ";
}
else
{
cout<<" Inverse of matrix is: ";
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
float res=((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]));
res=res/determinant;
cout<<res<<" ";
}
cout<<" ";
}
}
int main()
{ float a[3][3],i,j;
inputMatrxi(a);
display(a);
Inverse(a);
}
======================================================================
akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
The entered matrix is:
84 87 78
16 94 36
87 93 50
Inverse of matrix is:
-0.0065833 -0.0113552 0.0325757
-0.0141405 0.012592 0.00118324
0.0204511 0.00864789 -0.03167
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.