how to get basis vector from eigenvalues

2 ビュー (過去 30 日間)
Laura T
Laura T 2021 年 12 月 8 日
回答済み: sai charan sampara 2024 年 5 月 9 日
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?

回答 (1 件)

sai charan sampara
sai charan sampara 2024 年 5 月 9 日
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)
B = 5x5
2.3000 1.2500 -0.1000 -0.6500 -0.1000 1.2500 1.0000 0.5000 -0.7500 0.2500 -0.1000 0.5000 1.2000 -1.2000 0.7000 -0.6500 -0.7500 -1.2000 2.2000 -0.4500 -0.1000 0.2500 0.7000 -0.4500 0.7000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
[V,D]=eig(B)
V = 5x5
0.4082 0.2587 0.0518 -0.7121 0.5066 -0.6124 -0.5296 0.3352 -0.2109 0.4333 0.6124 -0.4114 0.3025 0.4820 0.3633 0.2041 -0.2089 0.6271 -0.3589 -0.6265 -0.2041 0.6632 0.6326 0.2954 0.1764
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
D = 5x5
-0.0000 0 0 0 0 0 0.1688 0 0 0 0 0 0.7128 0 0 0 0 0 2.4516 0 0 0 0 0 4.0667
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
[sorted_eigenvalues, idx] = sort(diag(D), 'descend')
sorted_eigenvalues = 5x1
4.0667 2.4516 0.7128 0.1688 -0.0000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
idx = 5x1
5 4 3 2 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
sorted_eigenvectors = V(:, idx);
basis_vector_1 = sorted_eigenvectors(:, 1)
basis_vector_1 = 5x1
0.5066 0.4333 0.3633 -0.6265 0.1764
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
basis_vector_2 = sorted_eigenvectors(:, 2)
basis_vector_2 = 5x1
-0.7121 -0.2109 0.4820 -0.3589 0.2954
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
[U,S,V] = svd(B)
U = 5x5
-0.5066 0.7121 -0.0518 0.2587 -0.4082 -0.4333 0.2109 -0.3352 -0.5296 0.6124 -0.3633 -0.4820 -0.3025 -0.4114 -0.6124 0.6265 0.3589 -0.6271 -0.2089 -0.2041 -0.1764 -0.2954 -0.6326 0.6632 0.2041
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
S = 5x5
4.0667 0 0 0 0 0 2.4516 0 0 0 0 0 0.7128 0 0 0 0 0 0.1688 0 0 0 0 0 0.0000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
V = 5x5
-0.5066 0.7121 -0.0518 0.2587 -0.4082 -0.4333 0.2109 -0.3352 -0.5296 0.6124 -0.3633 -0.4820 -0.3025 -0.4114 -0.6124 0.6265 0.3589 -0.6271 -0.2089 -0.2041 -0.1764 -0.2954 -0.6326 0.6632 0.2041
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
basis_vector_1 = U(:, 1)
basis_vector_1 = 5x1
-0.5066 -0.4333 -0.3633 0.6265 -0.1764
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
basis_vector_2 = U(:, 2)
basis_vector_2 = 5x1
0.7121 0.2109 -0.4820 0.3589 -0.2954
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by