Eigen Value and Eigen Vector Using Power Method
Given a matrix A such that the relation AX=ƛX holds, then X is called the Eigen-vector or characteristic vector and ƛ is called the Eigen-value or characteristic value of the matrix A.
The matrix equation can be rewritten as: (A-ƛI)X=0 , where I is the identity matrix of same order of matrix A.
There are some methods to find the Eigen value Æ› as well as Eigen vector of a matrix A such as the Iterative method, Power method, Jacobi method, many more. Here, we will limit ourselves to the Power Method of finding the Eigen Value and the Eigen Vector.
Power Method Algorithm
1. Read size of square matrix A, n
2. Read the matrix
3. Read the error limit ϵ
4. Initialize initial Eigen Vector X[n] (say with 1) and max=X[0]
5. Do
i. Tmax=max
ii. Calculate: Xi[n]=A[n][n]*Xi-1[n]
iii. Extract the maximum ‘max’ from Xi[n]
iv. Divide all element of Xi[n] with max
6. While(fabs(Tmax-max)>ϵ)
7. Eigen Value Æ›=max
8. Eigen Vector = X[n]
9. Print Æ› and X[n]
10. Stop
10. Stop
Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | #include <stdio.h> #include <math.h> #define SIZE 3 float max(float x[]) { float m = x[0]; int i; for (i = 0; i < SIZE; i++) { if (x[i] > m) m = x[i]; } return m; } void multiply(float a[SIZE][SIZE], float x[SIZE]) { int i, j, k; float sum; float temp[SIZE]; for (i = 0; i < SIZE; i++) { sum = 0; for (j = 0; j < SIZE; j++) { sum += a[i][j] * x[j]; } temp[i] = sum; } for (i = 0; i < SIZE; i++) x[i] = temp[i]; } void print(float X[SIZE]) { int i; printf("Eigen Vector : \n"); for (i = 0; i < SIZE; i++) { printf("%f ", X[i]); } printf("\n"); } int main() { float arr[SIZE][SIZE], X[SIZE]; int i, j, k = 0; float tmax, m, e; printf("Enter Element into %d X %d Matrix\n", SIZE, SIZE); for (i = 0; i < SIZE; i++) { for (j = 0; j < SIZE; j++) { printf("Enter Matrix[%d][%d] Element : ", i, j); scanf("%f", &arr[i][j]); } } printf("The Matrix Entered : \n"); for (i = 0; i < SIZE; i++) { for (j = 0; j < SIZE; j++) { printf("%f\t", arr[i][j]); } printf("\n"); } for (i = 0; i < SIZE; i++) { X[i] = 1; } printf("Enter Error Limit (Decimal Places) : "); scanf("%f", &e); e = pow(10, -e); m = 0; do { tmax = m; multiply(arr, X); m = max(X); for (i = 0; i < SIZE; i++) { X[i] /= m; } k++; } while (fabs(tmax - m) > e); printf("Eigen Value : %f\nNo. of Iterations : %d\n", m, k); print(X); } |
Output
Enter Element into 3 X 3 Matrix
Enter Matrix[0][0] Element : 2
Enter Matrix[0][1] Element : 4
Enter Matrix[0][2] Element : 6
Enter Matrix[1][0] Element : 3
Enter Matrix[1][1] Element : 9
Enter Matrix[1][2] Element : 15
Enter Matrix[2][0] Element : 4
Enter Matrix[2][1] Element : 16
Enter Matrix[2][2] Element : 36
The Matrix Entered :
2.000000 4.000000 6.000000
3.000000 9.000000 15.000000
4.000000 16.000000 36.000000
Enter Error Limit (Decimal Places) : 5
Eigen Value : 43.879990
No. of Iterations : 7
Eigen Vector :
0.185868 0.446032 1.000000
Enter Matrix[0][0] Element : 2
Enter Matrix[0][1] Element : 4
Enter Matrix[0][2] Element : 6
Enter Matrix[1][0] Element : 3
Enter Matrix[1][1] Element : 9
Enter Matrix[1][2] Element : 15
Enter Matrix[2][0] Element : 4
Enter Matrix[2][1] Element : 16
Enter Matrix[2][2] Element : 36
The Matrix Entered :
2.000000 4.000000 6.000000
3.000000 9.000000 15.000000
4.000000 16.000000 36.000000
Enter Error Limit (Decimal Places) : 5
Eigen Value : 43.879990
No. of Iterations : 7
Eigen Vector :
0.185868 0.446032 1.000000
0 comments:
Post a Comment