0% found this document useful (0 votes)
9 views

Eigen Value Using Power Method

Uploaded by

ad599066
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Eigen Value Using Power Method

Uploaded by

ad599066
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<stdio.

h>
#include<conio.h>
#include<math.h>
void main()
{

int i,j,n;
float A[40][40],x[40],z[40],e[40],zmax,emax;
printf("\nEnter the order of matrix:");
scanf("%d",&n);
printf("\nEnter matrix elements row-wise\n");
for(i=1; i<=n; i++){
for(j=1; j<=n; j++){
printf("A[%d][%d]=", i,j);
scanf("%f",&A[i][j]);
}
}
printf("\nEnter the column vector\n");
for(i=1; i<=n; i++){
printf("X[%d]=",i);
scanf("%f",&x[i]);
}
do
{
for(i=1; i<=n; i++){
z[i]=0;
for(j=1; j<=n; j++){
z[i]=z[i]+A[i][j]*x[j];
}
}
zmax=fabs(z[1]);
for(i=2; i<=n; i++){
if((fabs(z[i]))>zmax)
zmax=fabs(z[i]);
}
for(i=1; i<=n; i++){
z[i]=z[i]/zmax;
}
for(i=1; i<=n; i++){
e[i]=0;
e[i]=fabs((fabs(z[i]))-(fabs(x[i])));
}
emax=e[1];
for(i=2; i<=n; i++){
if(e[i]>emax)
emax=e[i];
}
for(i=1; i<=n; i++){
x[i]=z[i];
}
}
while(emax>0.001);
printf("\n The required eigen value is %f",zmax);
printf("\n\nThe required eigen vector is :\n");
for(i=1; i<=n; i++){
printf("%f\t",z[i]);
}
getch();
}
OUTPUT:
Enter the order of matrix:3 Enter the order of matrix:2

Enter matrix elements row-wise Enter matrix elements row-wise


A[1][1]=2 A[1][1]=2
A[1][2]=1 A[1][2]=1
A[1][3]=3 A[2][1]=3
A[2][1]=-2 A[2][2]=-1
A[2][2]=1
A[2][3]=0 Enter the column vector
A[3][1]=4 X[1]=2
A[3][2]=2 X[2]=3
A[3][3]=1
The required eigen value is 2.791796
Enter the column vector
X[1]=2 The required eigen vector is :
X[2]=1 1.000000 0.790962
X[3]=3
...Program finished with exit code 0
The required eigen value is 4.003649 Press ENTER to exit console.

The required eigen vector is :


1.000000 -0.665705 0.888973

...Program finished with exit code 0


Press ENTER to exit console.

You might also like