Can I assign a variable to a number in a matrix from another matrix?
3 ビュー (過去 30 日間)
古いコメントを表示
Anastasia Zistatsis
2021 年 3 月 2 日
コメント済み: Walter Roberson
2021 年 3 月 11 日
Using the matrix that comes from eig(), I would like to assign individual values in it to 3 separate variables, and then plug those into a separate matrix. However, I get an error. How do I do this?
E = eig(A)
E(1,1) = w1;
E(2,1) = w2;
E(3,1) = w3;
ans = [m1*w1^2 0 0;
0 m2*w2^2 0;
0 0 m3*w3^2 0]
Unrecognized function or variable 'w1'.
Error in eigen (line 23)
E(1,1) = w1;
0 件のコメント
採用された回答
Walter Roberson
2021 年 3 月 2 日
A = magic(7)
E = eig(A)
w1 = E(1,1)
w2 = E(2,1)
w3 = E(3,1)
m1 = 3; m2 = 11; m3 = -7;
output = [
m1*w1^2 0 0;
0 m2*w2^2 0;
0 0 m3*w3^2]
6 件のコメント
Walter Roberson
2021 年 3 月 11 日
syms k
A = [2*k -k -k;
-k 2*k -k;
-k -k 2*k];
E = eig(A)
If you are expecting 2.449 then your k would have to be roughly 0.816
その他の回答 (1 件)
Steven Lord
2021 年 3 月 2 日
There's a way to do this without creating 2*n individual variables.
A = magic(7);
E = eig(A);
w = E(1:3);
m = [3; 11; -7];
output1 = diag(m.*(w.^2))
w1 = E(1,1);
w2 = E(2,1);
w3 = E(3,1);
m1 = 3; m2 = 11; m3 = -7;
output2 = [ m1*w1^2 0 0;
0 m2*w2^2 0;
0 0 m3*w3^2]
You can compare output1 and output2. The first block of code scales to larger matrices with more eigenvalues.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!