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

Program To Find Eigen Values and Eigen Vectors by Power Method

This program uses the power method to find the eigenvalues and eigenvectors of a square matrix. It takes in the dimensions and elements of the matrix, the number of iterations, and an error limit. It iterates through the power method calculations, printing the eigenvalue and eigenvector at each step. It continues iterating until the change in eigenvalue between steps is less than the error limit, then outputs the closest eigenvalue and its eigenvector.

Uploaded by

Joyson Silva
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

Program To Find Eigen Values and Eigen Vectors by Power Method

This program uses the power method to find the eigenvalues and eigenvectors of a square matrix. It takes in the dimensions and elements of the matrix, the number of iterations, and an error limit. It iterates through the power method calculations, printing the eigenvalue and eigenvector at each step. It continues iterating until the change in eigenvalue between steps is less than the error limit, then outputs the closest eigenvalue and its eigenvector.

Uploaded by

Joyson Silva
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

//* Program to find Eigen values and Eigen vectors by Power method *//

#include<stdio.h>

#include<conio.h>

#include<math.h>

#include<stdlib.h>

int main()

int c,n,ni,i,j,k;

printf("Enter number of rows in the square matrix: n=");

scanf("%d",&n);

printf("\nEnter number of columns in the square matrix: c=");

scanf("%d",&c);

int a[n][n];

printf("Enter the matrix elements \n");

for(i=0;i<n;i++)

for(j=0;j<n;j++)

scanf("%d",&a[i][j]);

printf("\n");

printf("\nEnter the number of iterations: ni=");

scanf("%d",&ni);
float x[ni+1][n],el,ev[ni+1];

printf("\nEnter the Error limit:\t");

scanf("%f",&el);

for(i=0;i<(ni+1);i++)

for(j=0;j<n;j++)

x[i][j]=0;

printf("Enter the initial Eigen vector\n");

for(i=0;i<n;i++)

scanf("%f",&x[0][i]);

ev[i]=fabs(x[i][0]);

for(i=1;i<ni+1;i++)

for(j=0;j<n;j++)

for(k=0;k<n;k++)

x[i][j]=x[i][j]+(a[j][k]*x[i-1][k]);

ev[i]=fabs(x[i][0]);

for(j=1;j<n;j++)

if(ev[i]<fabs(x[i][j]))

ev[i]=fabs(x[i][j]);

for(j=0;j<n;j++)

x[i][j]=(x[i][j]/ev[i]);

printf("\n\nThe eigen value in %d iteration is %f",i,ev[i]);

printf("\nThe eigen vector in %d iteration is",i);

for(j=0;j<n;j++)

printf("\n\t%f",x[i][j]);
if(fabs(ev[i]-ev[i-1])<el)

goto end;

end:

if(i>ni)

i=i-1;

printf("\n\nThe closest eigen value found is %f",ev[i]);

printf("\nThe eigen vector is");

for(j=0;j<n;j++)

printf("\n\t%f",x[i][j]);

getch();

}
OUTPUT:

Enter number of rows in the square matrix: n=3

Enter number of columns in the square matrix: c=3

Enter the matrix elements

Enter the number of iterations: ni=9


Enter the Error limit: 0.01

Enter the initial Eigen vector

The eigen value in 1 iteration is 7.000000

The eigen vector in 1 iteration is

0.285714

0.571429

1.000000

The eigen value in 2 iteration is 11.714286

The eigen vector in 2 iteration is

0.451219

0.853658

1.000000

The eigen value in 3 iteration is 13.719512

The eigen vector in 3 iteration is

0.471111

0.880000

1.000000
The eigen value in 4 iteration is 13.937778

The eigen vector in 4 iteration is

0.472258

0.881378

1.000000

The eigen value in 5 iteration is 13.949936

The eigen vector in 5 iteration is

0.472307

0.881432

1.000000

The eigen value in 6 iteration is 13.950442

The eigen vector in 6 iteration is

0.472308

0.881433

1.000000

The closest eigen value found is 13.950442

The eigen vector is

0.472308

0.881433

1.000000

You might also like