how to get basis vector from eigenvalues
2 views (last 30 days)
Show older comments
Hi Guys,
I have i have just calculated the eigenvalue:
[V, D] = eig(B)
where previously B = cov(A) gave me a 5x5matrix.
How do i get the 2 basis vectors belonging to axes with the greatest variance? And how to get their corresponding variances?
0 Comments
Answers (1)
sai charan sampara
on 9 May 2024
Hello,
You can get the 2 basis vectors by simply sorting the eigen values in decreasing order and then usig the sorted indexes to index through the eigen vectors and get the vectors with the 2 largest eigen values as the basis vectors. The same is done in singular value decomposition done by "svd" function in MATLAB. Here is an example code:
A=randi(5,5);
B=cov(A)
[V,D]=eig(B)
[sorted_eigenvalues, idx] = sort(diag(D), 'descend')
sorted_eigenvectors = V(:, idx);
basis_vector_1 = sorted_eigenvectors(:, 1)
basis_vector_2 = sorted_eigenvectors(:, 2)
[U,S,V] = svd(B)
basis_vector_1 = U(:, 1)
basis_vector_2 = U(:, 2)
0 Comments
See Also
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!