Calculating the eigen vectors without using eig function but using a data set, the transpose of the data set and a unit vector
Afficher commentaires plus anciens
Hello,
I am trying to calculate the eigen vectors using a looped equation without using the eig function but using a dataset, the transpose, and a random unit vector with the magnitude of 1.
here is what I have so far:
clc
clear
A = importdata('mariana_depth.csv');
B=transpose (A);
C=B*A;
u=rand(1440,1); u=u/norm(u);
for i=1:10
u_n=u;
u=C*u
v(:,i)=u;
u_n(:,i) =u.*v(:,i)/norm(u.*v(:,i));
diffu = norm(u_n-u);
i
diffu
end
the problem I am having is that it is counting up but not down so I dont believe it it calculating the proper values of my eigen values.
1 commentaire
Zachary David
le 5 Avr 2022
Modifié(e) : Zachary David
le 5 Avr 2022
Réponses (2)
Sam Chak
le 5 Avr 2022
Can consider an alternative approach by finding the characteristic polynomial of a matrix using poly()
and then use some root-finding algorithms or roots() to find them.
For example:
A = [0 1; -2 -3]
p = poly(A)
r = roots(p)
A =
0 1
-2 -3
p =
1 3 2
r =
-2
-1
7 commentaires
Zachary David
le 5 Avr 2022
Zachary David
le 5 Avr 2022
Modifié(e) : Zachary David
le 5 Avr 2022
Zachary David
le 5 Avr 2022
There must be something stopping the iteration. Need to study your proposed algorithm and to compare with other algorithms:
- Power iteration
- Inverse iteration
- Rayleigh quotient iteration
- Arnoldi iteration — based on Krylov subspaces
- Lanczos algorithm — Arnoldi, specialized for positive-definite matrices
- Block Lanczos algorithm — for when matrix is over a finite field
- QR algorithm
- Jacobi eigenvalue algorithm — select a small submatrix which can be diagonalized exactly, and repeat
- Jacobi rotation — the building block, almost a Givens rotation
- Jacobi method for complex Hermitian matrices
- Divide-and-conquer eigenvalue algorithm
- Folded spectrum method
- LOBPCG — Locally Optimal Block Preconditioned Conjugate Gradient Method
- Eigenvalue perturbation — stability of eigenvalues under perturbations of the matrix
Zachary David
le 5 Avr 2022
Zachary David
le 5 Avr 2022
Sam Chak
le 5 Avr 2022
Think your method is related to the Power method. But the script below can only calculate the real largest eigenvalue.
function Demo_Eigen
close all
clc
A = [1 3 4; 5 6 7; 2 9 8]
% A = [0 1; -1 -1]
% A = inv(A) % Inverse Iteration Method to find smallest eigenvalue
n = size(A, 1);
x1 = ones(n, 1);
epsilon = 1e-6;
kmax = 100;
x(:, 1) = x1./norm(x1, 2); % initial eigenvector
x(:, 2) = A*x(:, 1);
lambda(2) = x(:, 1).'*x(:, 2); % initial eigenvalue
x(:, 2) = x(:, 2)./norm(x(:, 2), 2);
for k = 2:kmax
x(:, k+1) = A*x(:, k);
lambda(k + 1) = x(:, k).'*x(:, k + 1);
x(:, k + 1) = x(:, k + 1)./norm(x(:, k + 1), 2);
if abs(lambda(k + 1) - lambda(k)) < epsilon
break
end
end
Eigen_val = lambda(end)
Eigen_vec = x(:,end)
end
Your method give you the largest singular vector not eigen vector:
A=rand(5);
C=A'*A;
u=randn(size(A,2),1);
u=u/norm(u);
for i=1:100
u_n=C*u;
u_n=u_n/norm(u_n);
diffu = norm(u_n-u);
if diffu < 1e-10
fprintf('converge afeter %d iterations\n', i)
break
end
u=u_n;
end
u
[U,S,V]=svd(A);
V(:,1)
1 commentaire
If you want a smallest singular vector you need to use backslash instead of time
A = rand(5)
C=A'*A;
u=randn(size(A,2),1);
u=u/norm(u);
for i=1:100
u_n=C\u;
u_n=u_n/norm(u_n);
diffu = norm(u_n-u);
if diffu < 1e-10
fprintf('converge afeter %d iterations\n', i)
break
end
u=u_n;
end
u
[U,S,V]=svd(A);
V(:,end)
Catégories
En savoir plus sur Mathematics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!