# to develop a MATLAB program for eigenvalue solving using MATRIX ITERATION method

4 visualizzazioni (ultimi 30 giorni)
Risposto: Vinay il 8 Ago 2024
I am trying to create a program which will compute eigenvalue using matrix iteration method. I just know some basic commands and still learning. I have created the following function but I know it has a lot of errors and is not complete. Can anyone plz help
function l = ww(m,k)
for i=1:1000
for j=1:1000
m = [i 0 0;0 2*i 0;0 0 i];
k = [2*j -j 0;-j 7*j -4*j;0 -4*j 5*j];
end
end
n = length(m);
y = [];
x = [];
for i = 1:n % starting vector
x(i) = m(i,1);
end;
l = 0;
blad = k; % starting value of error
for i = 1:n % A*x
y(i) = 0;
for j = 1:n
y(i) = y(i) + m(i,j)*x(j);
end;
end;
l = 0; % Rayleigh
t = 0;
for i = 1:n
l = l + x(i)*y(i);
t = t + t(i)*x(i);
end;
l = l/t; % eigenvalue
x = y;
end;
end
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (1)

Vinay il 8 Ago 2024
Matrix iteration method calculates the eigen vector of a square matrix by starting with an initial guess for the eigen vector, repeatedly multiplying it by the matrix, and normalizing the result until convergence is achieved.
MATLAB function “rand” can be used for generating initial eigen vector and “norm” function for normalizing the eigen vector.
Kindly refer to the following documentations for “rand” and “norm” functions:
function [eigenvalue, eigenvector] = power_iteration(A, tol, max_iter)
% A: Square matrix
% tol: Tolerance
% max_iter: Maximum number of iterations
[~,n] = size(A);
% Initial guess for the eigenvector
b_k = rand(n, 1);
% Normalize the initial vector
b_k = b_k / norm(b_k);
% Iteration
for k = 1:max_iter
% Multiply by matrix A
b_k1 = A * b_k;
% Normalize the eigen vector
b_k1 = b_k1 / norm(b_k1);
% Check whether convergence is achieved
if norm(b_k1 - b_k) < tol
break;
end
% Update the eigen vector
b_k = b_k1;
end
% The dominant eigenvalue
eigenvalue = b_k' * A * b_k;
% The corresponding eigenvector
eigenvector = b_k;
end
% Example
A = [4, 1; 5, 3];
tol = 1e-6;
max_iter = 1000;
[eigenvalue, eigenvector] = power_iteration(A, tol, max_iter);
disp(['Dominant Eigenvalue: ', num2str(lambda)]);
disp('Corresponding Eigenvector:');
disp(eigenvector);
I hope this helps
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Linear Algebra in Help Center e File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by