Matlab code problem (calculate eigenvalues and eigenvectors)
古いコメントを表示
c0 = 2.4*1000;
c1 = 67*1000;
c2 = 58*1000;
c3 = 57*1000;
c4 = 50*1000;
c5 = 38*1000;
k0 = 1200*1000;
k1 = 33732*1000;
k2 = 29093*1000;
k3 = 28621*1000;
k4 = 24954*1000;
k5 = 19059*1000;
m1 = 6800;
m2 = 5897;
m3 = 5897;
m4 = 5897;
m5 = 5897;
m6 = 5897;
Mmat = [m1 0 0 0 0 0;
0 m2 0 0 0 0;
0 0 m3 0 0 0;
0 0 0 m4 0 0;
0 0 0 0 m5 0;
0 0 0 0 0 m6];
Kmat = [(k0+k1) -k1 0 0 0 0
-k1 (k1+k2) -k2 0 0 0
0 -k2 (k2+k3) -k3 0 0
0 0 -k3 (k3+k4) -k4 0
0 0 0 -k4 (k4+k5) -k5
0 0 0 0 -k5 k5];
A = Kmat/Mmat;
%Calculate eigenvalues and eigenvectors of A
[V,D] = eig(A);
%Check using det
det(A-D(1,1)*eye(6))
det(A-D(2,2)*eye(6))
det(A-D(3,3)*eye(6))
det(A-D(4,4)*eye(6))
det(A-D(5,5)*eye(6))
det(A-D(6,6)*eye(6))
Because the det values are larger than 0, there's something wrong with MATLAB. Please help me to check what's the problem. Thanks.
6 件のコメント
Torsten
2015 年 5 月 7 日
What do you get for the det-expressions ?
Maybe scaling your input matrices can reduce the error.
Best wishes
Torsten.
Jan
2015 年 5 月 7 日
@Yang Yu: please format your code properly. It is not readable.
the cyclist
2015 年 5 月 7 日
Yang Yu, I formatted it this time for you (so I could read it). For the future, please read this tutorial about how to use markup to make your question more readable.
John D'Errico
2015 年 5 月 7 日
編集済み: John D'Errico
2015 年 5 月 7 日
See that V and D satisfy the claimed property for those matrices, that
A*V - V*D
ans =
-4.5475e-12 -2.7285e-12 9.0949e-13 2.7285e-12 1.263e-12 6.8212e-13
9.0949e-12 5.457e-12 2.2737e-12 -1.7053e-13 -1.8066e-12 -1.08e-12
-5.457e-12 3.4106e-13 9.0949e-13 2.2737e-13 -7.6739e-13 -3.4106e-13
0 -5.457e-12 -3.1832e-12 -1.819e-12 4.9738e-14 -4.8317e-13
4.5475e-13 -9.0949e-13 0 -1.4779e-12 1.4388e-13 1.3642e-12
0 -1.3642e-12 -4.5475e-13 2.2737e-12 -2.5757e-13 -1.1369e-12
In the help for eig, we see this:
[V,D] = eig(A) produces a diagonal matrix D of eigenvalues and
a full matrix V whose columns are the corresponding eigenvectors
so that A*V = V*D.
However the resulting matrix of eigenvectors is not orthogonal.
V'*V
ans =
1 0.012472 -0.014293 0.017344 -0.015197 -0.019987
0.012472 1 -0.019237 0.023342 -0.020454 -0.0269
-0.014293 -0.019237 1 -0.026751 0.023441 0.030828
0.017344 0.023342 -0.026751 1 -0.028444 -0.037407
-0.015197 -0.020454 0.023441 -0.028444 1 0.032778
-0.019987 -0.0269 0.030828 -0.037407 0.032778 1
Oh, NEVER use det for ANY numerical test on a matrix. I don't care if your teacher told you to do so in some long forgotten class, or if you got this from some friend who said to use it. They were flat out wrong. The determinant is a sensitive thing that will not be reliable for any such computation. I know that some teachers still teach it. They see all those pretty results. How can it be wrong to teach their students to use it?
Torsten
2015 年 5 月 7 日
I still don't see why
det(A-D(i,i)*eye(6))
does not need to be zero (in theory) if the matrix A is defective.
Could you explain ?
Best wishes
Torsten.
John D'Errico
2015 年 5 月 7 日
編集済み: John D'Errico
2015 年 5 月 7 日
Well, for the det test it is easy to show what happens.
E = eig(A)
E =
17941
13379
8573.2
4213.6
31.232
1220.7
>> eig(A - E(5)*eye(6))
ans =
17910
13347
8542
4182.4
1.5323e-12
1189.5
>> prod(ans)
ans =
1.5566e+07
Again, this is why one should NEVER use det for ANY numerical test.
rank(A - E(5)*eye(6))
ans =
5
As I have said many times, floating point arithmetic is not truly mathematics. The differences are subtle. One looks a lot like the other, and the two have many similarities. But results that are true in mathematics will often fail to work in floating point arithmetic. And anything that involves a matrix determinant is often in the category of something to expect to fail miserably.
採用された回答
その他の回答 (2 件)
the cyclist
2015 年 5 月 7 日
編集済み: the cyclist
2015 年 5 月 7 日
Maybe I don't remember my matrix algebra well enough, but I don't understand what you are checking. Are you trying to prove that the eigenvectors are really eigenvectors? If so, then I would do
A*V(:,1) - D(1,1)*V(:,1)
A*V(:,2) - D(2,2)*V(:,2)
% etc
which is equal to zero (within expected error of floating point machine calculation).
You can also do those six calculations in one line as follows:
A*V - repmat(diag(D)',6,1).*V
Alfonso Nieto-Castanon
2015 年 5 月 7 日
編集済み: Alfonso Nieto-Castanon
2015 年 5 月 7 日
In your example the matrix A is not normal (check that A*A'-A'*A is not zero), hence it does not have a proper eigenvalue/eigenvector decomposition (it is not diagonalizable by a unitary matrix).
Depending on what exactly you are trying to accomplish I would suggest to try instead a singular value decomposition:
[Q,D,R] = svd(A);
which provides a somewhat similar decomposition (A = Q*D*R' with D diagonal, and Q and R orthonormal) for any matrix.
EDIT: also, Kmat is symmetric (and hence normal), so it is the division by the diagonal matrix Mmat (column-wise division of Kmat by the Mmat diagonal elements) that is breaking this symmetry and making the result non-normal, so I would suggest: a) checking where the Kmat/Mmat formula is coming from to make sure you got that right; and b) checking why would you expect the resulting A matrix to be diagonalizable to make sure you got that right as well.
カテゴリ
ヘルプ センター および File Exchange で Linear Algebra についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!