Created
November 17, 2018 18:54
-
-
Save mrfarhadir/f7adabdf3b97b29de7c9866436cc8811 to your computer and use it in GitHub Desktop.
Power Method Algoritym for calculating eig value and vector of matrix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [eigValue,eigVector] = EigPowerMethod (A, epsilon) | |
[m,n]=size(A); | |
if (m != n) | |
disp("Matrix Should Be Square"); | |
else | |
u = []; | |
t = 0; | |
r = ones(m); | |
u = [u transpose(r(1,:))]; | |
i = 2; | |
d = 1; | |
while(d > epsilon) | |
newU = A*u(:,i-1); | |
t = newU(m); | |
newU = newU/t; | |
u =[u newU]; | |
d = norm(u(:,i)-u(:,i-1)); | |
i++; | |
end | |
fprintf("repeats loop count : %d \r\n",i) | |
eigValue=t; | |
eigVector=u(:,i-1); | |
endif | |
endfunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A=[4 1;2 5] | |
A = | |
4 1 | |
2 5 | |
>> [val,vec]=EigPowerMethod(A,0.00000003) | |
repeats loop count : 26 | |
val = 6.00000008940697 | |
vec = | |
0.500000022351742 | |
1.000000000000000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment