0% found this document useful (0 votes)
59 views4 pages

Lab 10

The document contains three examples of using the Rayleigh power method to find the largest eigenvalues and eigenvectors of matrices. It provides the code to initialize the method, define parameters like the number of iterations and error tolerance, run the iterative calculation, and display the results. Each example shows the input matrix, code, and output table of iterations displaying the maximum value and eigenvector components.

Uploaded by

shriomraikar217
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views4 pages

Lab 10

The document contains three examples of using the Rayleigh power method to find the largest eigenvalues and eigenvectors of matrices. It provides the code to initialize the method, define parameters like the number of iterations and error tolerance, run the iterative calculation, and display the results. Each example shows the input matrix, code, and output table of iterations displaying the maximum value and eigenvector components.

Uploaded by

shriomraikar217
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Matrix Laboratory Manual

Lab 10) Finding largest and smallest eigenvalue by Rayleigh power method.
LAB 09) Solution of system of linear equations using Gauss-Seidel iteration.
Example 1:- Determine the largest eigen values and eigen vector
of the matrix
201
020
102
Algorithm
Step 1: Start
Step 2: Declare the variables (syms x y z )
Step 3: Read given matrix A
Step 4: Initialize vector v0 = v and
Step 5: Define the number of iterations to apply & absolute relative
approximate error
Step 6: Calculate length of second matrix(B)
Step6: Compute product of A and v0 = v
Step 7: Compute maximum value M of elements in v Divide v = v/M.
Step 8: Store the iteration in matrix form
Step 9: Check for the absolute relative approximate error
Step10: If iteration value is less than approximate error go to step 7
Step11: Display the Solution
Step12: End

Code:
A =[2 0 1; 0 2 0; 1 0 2] %intitial input matrix
v =[1;0;0] %initial choice of eigenvector
n=8; % nuumber of iteration
e = 1e-4 ; % tolerance of error
v0=v ;
N = length(v);
E =zeros(N,N); % initial matrix to store iteration
F=[0;0;0]; % initial matrix to Maximum Value
index=1;

for i = 1:n
v = A*v0 ;
M = max(v) ; %maximum value M of elements in v
v = v/M; %fresh value v

Department of Mathematics KLE Institute of Technology


Matrix Laboratory Manual

if abs(v-v0)<e
break
end

v0 = v;
E(index,:)=v();
F(index,:)=M();
index=index+1;
end

% Display the solution in form of table


p=[F,E];
V={'Max','x', 'y','z'};
T = array2table(p,'VariableNames',V)

Output:
T = 8×4 table

Max x y z
1 2 1 0 0.5000
2 2.5000 1 0 0.8000
3 2.8000 1 0 0.9286
4 2.9286 1 0 0.9756
5 2.9756 1 0 0.9918
6 2.9918 1 0 0.9973
7 2.9973 1 0 0.9991
8 2.9991 1 0 0.9997

Department of Mathematics KLE Institute of Technology


Matrix Laboratory Manual

Example 1:- Determine the largest eigen values and eigen vector
of the matrix
2 -1 0
-1 2 -1
0 -1 2
Code:
A =[2 -1 0; -1 2 -1; 0 -1 2] %intitial input matrix
v =[1;0;0] %initial choice of eigenvector
n=8; % nuumber of iteration
e = 1e-4 ; % tolerance of error
v0=v ;
N = length(v);
E =zeros(N,N);
F=[0;0;0];
index=1;
for i = 1:n
v = A*v0 ;
M = max(v) ; %maximum value M of elements in v
v = v/M; %fresh value v
if abs(v-v0)<e
break
end
v0 = v;
E(index,:)=v();
F(index,:)=M();
index=index+1;
end
p=[F,E];
V={'Max','x', 'y','z'};
T = array2table(p,'VariableNames',V)
T = 8×4 table

Max x y z
1 2 1 -0.5000 0
2 2.5000 1 -0.8000 0.2000
3 2.8000 1 -1 0.4286
4 3 1 -1.1429 0.6190
5 3.1429 1 -1.2424 0.7576
6 3.2424 1 -1.3084 0.8505
7 3.3084 1 -1.3503 0.9096
8 3.3503 1 -1.3761 0.9460
Department of Mathematics KLE Institute of Technology
Matrix Laboratory Manual

Example 3:- Determine the largest eigen values and eigen vector of the
matrix
25 1 2
1 3 0
2 0 -4
Code:
A =[25 1 2; 1 3 0; 2 0 -4] %intitial input matrix
v =[1;0;0] %initial choice of eigenvector
n=8; % nuumber of iteration
e = 1e-4 ; % tolerance of error
v0=v ;
N = length(v);
E =zeros(N,N);
F=[0;0;0];
index=1;
for i = 1:n
v = A*v0 ;
M = max(v) ; %maximum value M of elements in v
v = v/M; %fresh value v
if abs(v-v0)<e
break
end
v0 = v;
E(index,:)=v();
F(index,:)=M();
index=index+1;
end
p=[F,E];
V={'Max','x', 'y','z'};
T = array2table(p,'VariableNames',V)
T = 4×4 table

Max x y z
1 25 1 0.0400 0.0800
2 25.2000 1 0.0444 0.0667
3 25.1778 1 0.0450 0.0688
4 25.1827 1 0.0451 0.0685

Department of Mathematics KLE Institute of Technology

You might also like