findging eigenvectors with eigenvalues
Show older comments
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.
Accepted Answer
More Answers (0)
Categories
Find more on Linear Algebra in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!