findging eigenvectors with eigenvalues
15 ビュー (過去 30 日間)
古いコメントを表示
clc; clear;
% Given matrix A
A = [3.6574, -1.9723, 0, 0.8581, 3.0865;
0.5177, 1.4469, 0, 1.1376, -3.7955;
-0.7951, 0.1142, 0.7290, -0.5829, -0.2565;
-0.7273, 2.1819, 0, 2.2816, -6.5275;
0.4301, -1.2904, 0, -0.8602, 3.5590];
% Convergence criterion
tol = 1e-5;
% Number of eigenvalues to find
num_eigenvalues = 3;
% Allocate space for eigenvalues and eigenvectors
eigenvalues = zeros(num_eigenvalues, 1);
eigenvectors = zeros(size(A, 1), num_eigenvalues);
% Function to compute eigenvalues and eigenvectors using inverse iteration and deflation
function [lambda, v] = inverse_iteration(A, x0, tol, max_iter)
v = x0 / norm(x0); % Normalize initial vector
I = eye(size(A));
for k = 1:max_iter
w = (A - I) \ v; % Solve linear system
v_new = w / norm(w); % Normalize new vector
lambda = v_new' * A * v_new; % Estimate eigenvalue
if norm(v_new - v, inf) < tol % Check for convergence
v = v_new;
return;
end
v = v_new;
end
end
% Initial guess for eigenvector
x0 = [1; 0; 0; 0; 0];
% Find the three smallest eigenvalues and eigenvectors using inverse iteration and deflation
for i = 1:num_eigenvalues
[lambda, v] = inverse_iteration(A, x0, tol, 1000);
eigenvalues(i) = lambda;
eigenvectors(:, i) = v;
% Deflation step
A = A - lambda * (v * v');
% Restart with a new initial vector
x0 = rand(size(A, 1), 1);
end
% Display results
disp('Eigenvalues:');
disp(eigenvalues);
disp('Eigenvectors:');
disp(eigenvectors);
This question is about finding 3 smallest eigenvalues and corresponding eigenvectors. If I run this code eigenvlaues work well but each of eigenvalue's eigenvector comes out wrong could someone modify my code do it can work well?
1. Use the inverse iteration and deflation to find three smallest (in magnitude) eigenvalues and corresponding eigenvectors of the following matrix. Start with an initial eigenvector of (1, 0, 0, 0, 0)T for the power method, and use ∥x(k+1) − x(k)∥∞ ≤ 10−5 as a stopping criteria for your iteration. Approximate the eigenvalues using the Rayleigh Quotient.
0 件のコメント
採用された回答
John D'Errico
2024 年 5 月 25 日
編集済み: John D'Errico
2024 年 5 月 25 日
Most of the time when I see someone worry their eigenvectors are not correct, it is just because of a sign error on the eigenvectors. But in this case, your code is incorrect, and I would suggest you have one other subtle issue. First, I would note that your eigenvalues are not coming out in the correct order. The inverse power method should find the smallest eigenvalue first. And that alone tells me there is an issue in your code.
A = [3.6574, -1.9723, 0, 0.8581, 3.0865;
0.5177, 1.4469, 0, 1.1376, -3.7955;
-0.7951, 0.1142, 0.7290, -0.5829, -0.2565;
-0.7273, 2.1819, 0, 2.2816, -6.5275;
0.4301, -1.2904, 0, -0.8602, 3.5590];
[V,D] = eig(A);
D = diag(D)
Now, suppose you find the smallest eigenvalue of A, and then deflate A?
vec = V(:,5);
lambda = D(5);
Ahat = A - lambda*vec*vec'
Now, what are the eigenvalues of Ahat, after deflation?
eig(Ahat)
What is the SMALLEST eigenvalue of Ahat? ZERO. So now what will the inverse power method find when you apply it to the matrix Ahat? Things will now get confusing. The inverse power method will now "think" the smallest eigenvalue of Ahat is ZERO.
This tells us that we cannot use a simple deflation scheme, shifting things so the smallest eigenvalue is zero.
What else can we do? If we are using the inverse power method, one idea might be to shift that eigenvalue to something large instead.
lambdashift = max(sum(abs(A),2))*1.1;
You should be able to show that lambdashift is indeed larger in magnitude than any possible eigenvalue of A. We can try using that as a shift instead.
Ahat2 = A + (lambdashift - lambda)*vec*vec';
eig(Ahat2)
As you should see, this leaves the other small eigenvalues of A unchanged. And now the inverse power method will be able to again find the smallest eigenvalue.
Finally, there is the issue of your code to solve for the smallest eigenvalue/vector, using the inverse power method. That still needs to be fixed...
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!