[Solved] Power method, eigenvalues.
Ältere Kommentare anzeigen
function l = ww(A,E)
n = length(A);
y = [];
x = [];
for i = 1:n % starting vector
x(i) = A(i,1);
end;
l = 0;
blad = E; % starting value of error
while blad>=E
for i = 1:n % A*x
y(i) = 0;
for j = 1:n
y(i) = y(i) + A(i,j)*x(j);
end;
end;
blad = l;
l = 0; % Rayleigh
m = 0;
for i = 1:n
l = l + x(i)*y(i);
m = m + x(i)*x(i);
end;
l = l/m; % eigenvalue
blad = abs(l - blad); % error
x = y;
end;
end
That's how I've tried to compute eigenvalues. It works for some matrices, but for:
A =
0 -0.3333 -0.3333
-0.3333 0 0.3333
0.6000 0.2000 0
it doesn't work. How can I fix that?
7 Kommentare
Walter Roberson
am 12 Mai 2011
What difference do you see between what you expect and what is output?
Matt Fig
am 12 Mai 2011
And what is the input E??
John D'Errico
am 12 Mai 2011
Wow. Looks just like Fortran code to me.
Andrew Newell
am 13 Mai 2011
Fortran 77; 90 has vector operations.
Kamil
am 13 Mai 2011
Lorenzo Amabili
am 17 Mär. 2017
Bearbeitet: Lorenzo Amabili
am 17 Mär. 2017
@Kamil
@Teja Muppirala
how do you set E initially? I am sorry in case this question is silly but I am still new to this field. Thank you!
karim hamza
am 29 Apr. 2017
i have an error [not enough input argument]
Akzeptierte Antwort
Weitere Antworten (3)
Andrew Newell
am 12 Mai 2011
While we wait for more information, here is a vectorized version of whatever your algorithm is doing:
function l = ww(A,E)
x = A(:,1);
l = 0;
blad = E; % starting value of error
while blad>=E
y = A*x;
blad = l;
l = x.*y; % Rayleigh
m = x.*x;
l = l/m; % eigenvalue
blad = abs(l - blad); % error
x = y;
end;
2 Kommentare
devalaraju venkata naga amulya
am 24 Jul. 2019
when i run the above code there is an error of input values A and E(in line function) can u help it with me im sorry im very new to the matlab
Dhruv Bhavsar
am 28 Aug. 2020
Try calling the function in the command prompt even if you get the above mentioned error.
If it works then copy the function at the bottom of a new script and write the codes to be implemented above the function defined.
I have attached my code file for your reference.
Kamil
am 13 Mai 2011
0 Stimmen
Akankshya
am 13 Feb. 2024
0 Stimmen
function l = ww(A,E)
x = A(:,1);
l = 0;
blad = E; % starting value of error
while blad>=E
y = A*x;
blad = l;
l = x.*y; % Rayleigh
m = x.*x;
l = l/m; % eigenvalue
blad = abs(l - blad); % error
x = y;
end
Kategorien
Mehr zu Linear Algebra finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!