bug su power method, aggiunto calcolo autovalori con matrici simili
This commit is contained in:
12
functions/eigenvalues.m
Normal file
12
functions/eigenvalues.m
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
function [ values, err ] = eigenvalues( A, ite, toll )
|
||||||
|
|
||||||
|
i=0;
|
||||||
|
err = inf;
|
||||||
|
while (i < ite) && (err > toll)
|
||||||
|
[q,r] = qr(A);
|
||||||
|
A1= r * q
|
||||||
|
err = norm(diag(A1) - diag(A),inf) / norm (diag(A1),inf);
|
||||||
|
A = A1;
|
||||||
|
i=i+1;
|
||||||
|
end
|
||||||
|
values = diag(A);
|
||||||
@@ -1,22 +1,22 @@
|
|||||||
|
|
||||||
|
|
||||||
function [v,a] = power_method (U,toll)
|
function [vn,a] = power_method (U,toll)
|
||||||
|
|
||||||
[x,~] = size(U);
|
[x,~] = size(U);
|
||||||
for i=1:x
|
for i=1:x
|
||||||
v(i)=1;
|
v(i)=1;
|
||||||
end
|
end
|
||||||
v=v';
|
v=v';
|
||||||
|
vn=v;
|
||||||
|
|
||||||
err = inf;
|
err = inf;
|
||||||
while err > toll
|
while err > toll
|
||||||
|
|
||||||
v1=U*v;
|
v1=U*v;
|
||||||
v1=v1./norm(v1,inf);
|
v1n=v1./norm(v1,inf);
|
||||||
err = norm(v1-v,inf);
|
err = norm(v1n-vn,inf);
|
||||||
a = v1./v;
|
a = v1./v;
|
||||||
v=v1;
|
v=v1;
|
||||||
|
vn=v1n;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
3
samples/similar matrix.m
Normal file
3
samples/similar matrix.m
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
B = inv(S) * A * S;
|
||||||
|
|
||||||
|
A e B sono simili e hanno gli stessi autovalori
|
||||||
Reference in New Issue
Block a user