필터 지우기
필터 지우기

Picking eigenvalues below a certain value.

조회 수: 4 (최근 30일)
John Smith
John Smith 2016년 5월 26일
답변: the cyclist 2016년 5월 26일
I have a problem where I have, lets say 1000 2x2 random matrices distributed with mean 0 and variance 1. I have to find the eigenvalues below 0.3 and use their corresponding eigenvectors to calculate a quantity from it. So far I have the following code for this exact type of problem:
[V,D] = eig(H);
d = diag(D);
idx = abs(d)<0.3;
E1 = d(idx);
E2 = V(:,idx);
The problem that I'm having is that because the matrices are random in some cases there will be no eigenvalues less than 0.3 and so when that gets put into the calculation Matlab just outputs NaN or Inf. Is there a way to ignore those and only use the matrices where they have eigenvalues less than 0.3?
  댓글 수: 1
John D'Errico
John D'Errico 2016년 5월 26일
Be careful, as in some cases, there might be 0, 1, or 2 eigenvalues that satisfy the requirement.

댓글을 달려면 로그인하십시오.

답변 (1개)

the cyclist
the cyclist 2016년 5월 26일
You could insert subsequent code inside a statement like
if any(idx)
...
end
To guard against there being multiple eigenvalues meeting the criterion, you could change that condition to
if sum(idx)==1
...
end
Of course, the correct approach will depend on how you want to handle these different cases.
You could use a switch/case construct to do different things for different cases.

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by