-
-
Save AmanSinghBhogal/1480048c7ae89934220bd182135b7592 to your computer and use it in GitHub Desktop.
Program for Determinant, characteristic equation,etc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Program to solve questions based on eigen value and eigen vector. | |
//This is going to be a menu driven program. Following operations would be made possible by this code: | |
//1. Find Determinant of an inserted matrix. | |
//2. See if Matrix is consistant or not. | |
//3. Finding sqquare of a Matrics . | |
//4. Finding cube of a Matrix. | |
//5. Finding product of two Matrix. | |
//6. Finding Characteristic equation of a matrix. | |
char const p_2= 253; //power to 2 superscript. | |
//char const p_3= 254; | |
#include<iostream> | |
using namespace std; | |
class game | |
{ | |
private: | |
int order, A[5][5],B[5][5],result[5][5],choice; | |
public: | |
game() | |
{ | |
order= 5; | |
for(int i=0;i<order;i++) | |
{ | |
for(int j=0;j<order;j++) | |
{ | |
result[i][j]=0; | |
B[i][j]=0; | |
} | |
} | |
} | |
void menu(); | |
void display(); | |
void Det(); | |
void sq(); | |
void cube(); | |
void mul(); | |
void char_eq(); | |
}; | |
void game::display() | |
{ | |
system("cls"); | |
cout<<"Program to Simplify MTT Questions by reducing Time in lathargic calculation."<<endl; | |
} | |
void game::menu() | |
{ | |
display(); | |
cout<<"MENU:"<<endl; | |
cout<<"\nOperations available are:"<<endl; | |
cout<<"1. To find Determinant of a Given Matrix."<<endl; | |
cout<<"2. To find the Characteristic Equation of a given Matrix."<<endl; | |
cout<<"3. To find the Square of a Matrix."<<endl; | |
cout<<"4. To find the Cube of a given Matrix."<<endl; | |
cout<<"5. To find the product of two Matrix."<<endl; | |
cout<<"Enter the your choice:"; | |
cin>>choice; | |
if(choice==1) | |
Det(); | |
else if(choice==2) | |
char_eq(); | |
else if(choice==3) | |
sq(); | |
else if(choice==4) | |
cube(); | |
else if(choice==5) | |
mul(); | |
else | |
{ | |
exit(0); | |
} | |
} | |
void game::Det() | |
{ | |
display(); | |
cout<<"\n\nOperation Number: 1, Finding Determinant of a Matrix."<<endl; | |
cout<<"\nEnter Order of the Matrix:"; | |
cin>>order; | |
cout<<"Enter the Matrix:"<<endl; | |
for(int i=0;i<order;i++) | |
{ | |
for(int j=0;j<order;j++) | |
cin>>A[i][j]; | |
} | |
if(order==2) | |
cout<<"The Determinant of the given Matrix is: "<<((A[0][0]*A[1][1])-(A[0][1]*A[1][0]))<<endl; | |
else if(order==3) | |
cout<<"The Determinant of the given Matrix is: "<<((A[0][0]*((A[1][1]*A[2][2])-(A[1][2]*A[2][1]))) - (A[1][0]*((A[0][1]*A[2][2])-(A[0][2]*A[2][1]))) + (A[2][0]*((A[0][1]*A[1][2])-(A[0][2]*A[1][1]))))<<endl; | |
else | |
cout<<"Sorry the Program is not designed to find determinant of matrix of order greater than 3, yet."<<endl; | |
} | |
void game::char_eq() | |
{ | |
display(); | |
cout<<"\nOperation to find the Characteristic equation of a given Matrix."<<endl; | |
cout<<"Enter the order of the Matrix:"; | |
cin>>order; | |
cout<<"Enter the Matrix A:"<<endl; | |
for(int i=0;i<order;i++) | |
{ | |
for(int j=0;j<order;j++) | |
cin>>A[i][j]; | |
} | |
if(order==2) | |
{ | |
cout<<"The Characteristic Equation of the given Matrix is: A"<<(char)p_2<<" - "<<(A[0][0]+A[1][1])<<"A +"<<((A[0][0]*A[1][1])-(A[0][1]*A[1][0]))<<endl; | |
} | |
else if(order==3) | |
{ | |
int n=((A[0][0]*((A[1][1]*A[2][2])-(A[1][2]*A[2][1]))) - (A[1][0]*((A[0][1]*A[2][2])-(A[0][2]*A[2][1]))) + (A[2][0]*((A[0][1]*A[1][2])-(A[0][2]*A[1][1])))); | |
int q= ((A[0][0]*A[1][1]) + (A[1][1]*A[2][2]) + (A[0][0]*A[2][2])-(A[0][1]*A[1][0]) - (A[0][2]*A[2][0]) - (A[1][2]*A[2][1])); | |
cout<<"The Characteristic Equation of the given Matrix is: A^3 + ("<<-1*(A[0][0]+A[1][1]+A[2][2])<<")A"<<(char)p_2<<" + ("<<q<<")A +("<<-1*n<<")"<<endl; | |
} | |
} | |
void game::sq() | |
{ | |
display(); | |
cout<<"\nOperation to find square of a given matrix."<<endl; | |
cout<<"Enter the order of the Matrix:"; | |
cin>>order; | |
cout<<"Enter the Matrix A:"<<endl; | |
for(int i=0;i<order;i++) | |
{ | |
for(int j=0;j<order;j++) | |
cin>>A[i][j]; | |
} | |
for(int i=0;i<order;i++) | |
{ | |
for(int j=0;j<order;j++) | |
{ | |
for(int k=0;k<order;k++) | |
{ | |
result[i][j]+=(A[i][k]*A[k][j]); | |
} | |
} | |
} | |
cout<<"The Square of the Matrix is:"<<endl; | |
cout<<"A"<<(char)p_2<<":"<<endl; | |
for(int i=0;i<order;i++) | |
{ | |
for(int j=0;j<order;j++) | |
{ | |
cout<<result[i][j]<<" "; | |
} | |
cout<<endl; | |
} | |
} | |
void game::cube() | |
{ | |
display(); | |
cout<<"\nOperation to find Cube of a given matrix."<<endl; | |
cout<<"Enter the order of the Matrix:"; | |
cin>>order; | |
cout<<"Enter the Matrix A:"<<endl; | |
for(int i=0;i<order;i++) | |
{ | |
for(int j=0;j<order;j++) | |
cin>>A[i][j]; | |
} | |
for(int i=0;i<order;i++) | |
{ | |
for(int j=0;j<order;j++) | |
{ | |
for(int k=0;k<order;k++) | |
{ | |
B[i][j]+=(A[i][k]*A[k][j]); | |
} | |
} | |
} | |
for(int i=0;i<order;i++) | |
{ | |
for(int j=0;j<order;j++) | |
{ | |
for(int k=0;k<order;k++) | |
{ | |
result[i][j]+=(A[i][k]*B[k][j]); | |
} | |
} | |
} | |
cout<<"The Cube of the Matrix is:"<<endl; | |
cout<<"A^3"<<":"<<endl; | |
for(int i=0;i<order;i++) | |
{ | |
for(int j=0;j<order;j++) | |
{ | |
cout<<result[i][j]<<" "; | |
} | |
cout<<endl; | |
} | |
} | |
void game::mul() | |
{ | |
display(); | |
cout<<"\nOperation to find product of a two given matrix."<<endl; | |
cout<<"Enter the order of the Matrix:"; | |
cin>>order; | |
cout<<"Enter the Matrix A:"<<endl; | |
for(int i=0;i<order;i++) | |
{ | |
for(int j=0;j<order;j++) | |
cin>>A[i][j]; | |
} | |
cout<<"Enter the Matrix B:"<<endl; | |
for(int i=0;i<order;i++) | |
{ | |
for(int j=0;j<order;j++) | |
cin>>B[i][j]; | |
} | |
for(int i=0;i<order;i++) | |
{ | |
for(int j=0;j<order;j++) | |
{ | |
for(int k=0;k<order;k++) | |
{ | |
result[i][j]+=(A[i][k]*B[k][j]); | |
} | |
} | |
} | |
cout<<"The Product of the two Matrix is:"<<endl; | |
cout<<"A.B"<<":"<<endl; | |
for(int i=0;i<order;i++) | |
{ | |
for(int j=0;j<order;j++) | |
{ | |
cout<<result[i][j]<<" "; | |
} | |
cout<<endl; | |
} | |
} | |
int main() | |
{ | |
char ch; | |
do | |
{ | |
game o; | |
o.menu(); | |
cout<<"Do you want to Quit?(y-Yes/n-No):"; | |
cin>>ch; | |
} while (ch=='n'||ch=='N'); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment