-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheigenvalue_vector.m
More file actions
31 lines (26 loc) · 882 Bytes
/
eigenvalue_vector.m
File metadata and controls
31 lines (26 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function [X, lambda] = eigenvalue_vector(A)
s = size(A);
% creating the identity matrix
I = eye(length(A));
syms x
% equation to be solved for compute eigenvalues
eq1 = det(A - I*x) == 0;
% solving the equation wrt x to get the eigenvalues
eigval = double(solve(eq1, x));
% arranging the eigenvalues in form of a diagnol matrix
lambda = zeros(length(eigval));
for i = 1:size(eigval)
lambda(i, i) = eigval(i);
end
X = zeros(s);
% computing eigenvectors iteratively from the eigenvalues
for i = 1:length(A)
if eigval(i) == 0
continue;
end
% computing the RHS of homogenous eqn to compute eigenvectors
mat = A - eigval(i)*I;
% finding the null space of homogenous eqns i.e. the requied eigenvectors
X(:, i) = null(mat);
end
end