# Eigenvalue Extraction by Power Method

#include<stdio.h> #include<conio.h> #include<math.h> int main() { printf("\n Eigen Value Extraction Power Method \n"); // variable declaration int i,j,k,nv; printf("\nEnter the size of the matrix:\t"); scanf("%d",&nv); float matA[30][30],err,temp,total=0; float b[30],c[30],d[30],max,con,min=0; for(i=0;i<nv;i++) { // Getting the coefficients of the matrix for(j=0;j<nv;j++) { printf("\nEnter the element[%d][%d]: ",i+1,j+1); scanf("%f",&matA[i][j]); } } // Getting the trial vector top: printf("\nEnter the trial vector:\t"); for(i=0;i<nv;i++) {

j++) b[i]+=matA[i][j]*c[j]. for(i=0.i++) b[i]=0.i++) { if(fabsl(b[i])> fabsl(max)) max=b[i]. . scanf("%f".i<nv.&c[i]).i++) d[i]=0. for(i=0.j<nv.i++) { b[i]/=fabsl(max). } max=0. // logic to find the eigenvalues and eigenvectors do{ for(i=0.i++) { for(j=0.i<nv. for(i=0.i<nv.i<nv.printf("\nEnter the trial vector row%d:\t". i+1). scanf("%f". } // Getting the error limit printf("\nEnter the error limit: ").&err). for(i=0. } con=0.i<nv.

//Printing the Eigenvalues and Eigenvectors if (min==0) { printf("\nThe maximum Eigenvalue is "). else con+=1.b[i]). for(i=0. temp=max. if(fabsl(fabsl(b[i])-fabsl(d[i]))<err) con+=0.i+1. } else { printf("\nThe minimum Eigenvalue is "). } printf("%f". } if (min==0) { for(i=0. } }while(con!=0).max).i++) { printf("\n Corresponding Eigenvector A%d is %f". max=temp-max.i<nv. d[i]=b[i].i<nv.c[i]=b[i].i++) .

j++) if(i==j) { total+=matA[i][j]. goto top. total). } if(nv==3) { total-=(max+temp). } getch(). } .for(j=0. return 0. printf("\n\nThe other Eigenvalue is %f". } min=1.j<nv. matA[i][j]-=max. printf("\n\nTo find the minimum Eigenvalue: \n").