#include<iostream.h>
//#include<conio.h>
#include<math.h>
#define max 2
class matrix
{
private :
int num[max][max];
int rt1,rt2;
int egn1[max][1],egn2[max][1];
public :
void inp_mat()
{
cout<<"\n\n Enter the elements in the matrix";
for(int i=0;i<max;i++)
{
cout<<"\n Enter elements for Row#"<<i+1<<" : ";
for(int j=0;j<max;j++)
cin>>num[i][j];
}
}
void fnd_egn()
{
int a,b,c,det,quo;
a = 1;
b = -(num[0][0]+num[1][1]);
c = (num[0][0]*num[1][1])-(num[0][1]*num[1][0]);
cout<<"\n Its' characterristic equation is : "<<a<<"*x*x + "<<b<<"*x +"<<c;
det = b*b - 4*a*c;
rt1 = (-b+sqrt(det))/(2*a);
rt2 = (b+sqrt(det))/(2*a);
cout<<"\n\n And, the Eigenvalues are : "<<rt1<<" and "<<rt2;
a = num[0][0] - rt1;
b = num[0][1];
quo = a>b?-a/b:-b/a;
if(quo>0)
{
egn1[0][0] = quo;
egn1[1][0] = 1;
}
else
{
egn1[1][0] = quo;
egn1[0][0] = 1;
}
cout<<"\n\n The Eigenvector correspoding to Eigenvalue "<<rt1;
cout<<"\n\n\t\t"<<egn1[0][0]<<"\n\t\t"<<egn1[1][0];
a = num[0][0] - rt2;
b = num[0][1];
quo = a>b?-a/b:-b/a;
if(quo>0)
{
egn2[0][0] = quo;
egn2[1][0] = 1;
}
else
{
egn2[1][0] = quo;
egn2[0][0] = 1;
}
cout<<"\n\n The Eigenvector correspoding to Eigenvalue "<<rt2;
cout<<"\n\n\t\t"<<egn2[0][0]<<"\n\t\t"<<egn2[1][0];
}
};
int main()
{
//clrscr();
matrix mat;
mat.inp_mat();
mat.fnd_egn();
// getch();
return 0;
}
No comments:
Post a Comment