#include<iostream>
#include<math.h>
using namespace std;
int main()
{
float a[10][10],x[10],c[10],ev=0,t;
int i,j,n;
cout<<"Enter the order of matrix= ";
cin>>n;
cout<<"Enter the Coefficients of matrix row-wise\n";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
cin>>a[i][j];
}
cout<<"Enter the starting vector\n";
for(i=0;i<n;i++)
cin>>x[i];
do
{
for(i=0;i<n;i++)
{
c[i]=0;
for(j=0;j<n;j++)
c[i]+=a[i][j]*x[j];
}
for(i=0;i<n;i++)
x[i]=c[i];
t=ev;
ev=0;
for(i=0;i<n;i++)
{
if(fabs(x[i])>fabs(ev))
ev=x[i];
}
for(i=0;i<n;i++)
x[i]/=ev;
}while(fabs(ev-t)>0.0001);
cout<<"\nThe Eigen value is : "<<ev<<endl;
cout<<"\nThe Eigen Vector is: ";
for(i=0;i<n;i++)
cout<<"\n"<<x[i];
return 0;
}
No comments:
Post a Comment