A lot of eigenvalues

조회 수: 3 (최근 30일)
tomas
tomas 2011년 8월 23일
Hello everybody!
I have many 3x3 matrixes (e.g. 3 000 000 matrixes) and I need to compute their eigenvalues. Nowadays, I'm doing it in loop having 3 000 000 counts, but this way is very time consuming. I'd like to know if there is any possibility how to replace the loop by some matrix operation. For example, I can make a 3x3x3000000 matrix from which I would get the eigenvalues, somehow?
Can anybody help with this?
Thank you in advance,
Tom
  댓글 수: 1
Oleg Komarov
Oleg Komarov 2011년 8월 23일
c(1:3e6) = {rand(3)};
tic
egv = cellfun(@eig,c,'un',0);
toc
23 seconds to me it seems fair.

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

채택된 답변

Doug Hull
Doug Hull 2011년 8월 23일
This from Oleg seems like an answer, not a comment. I prefer to see questions in the 'answered' state.
c(1:3e6) = {rand(3)};
tic
egv = cellfun(@eig,c,'un',0);
toc
23 seconds to me it seems fair.
  댓글 수: 3
tomas
tomas 2011년 8월 24일
Olegs answer works. Although I don't understand last two input parameters of cellfun function - 'un',0. Can you tell me what they mean, please?
Thank you guys.
Daniel Shub
Daniel Shub 2011년 8월 24일
They are shorthand for 'uniform' and false

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

추가 답변 (1개)

Daniel Shub
Daniel Shub 2011년 8월 24일
While the loop is ~20% slower on my machine then using cellfun, the answer is in a double array and not a cell array. There may be hidden costs of getting the information from the cell array into a usable form.
N = 3e6;
x = rand(3, 3, N);
tic
egv = zeros(3, N);
for ii = 1:N
egv(:, ii) = eig(x(:, :, ii));
end
toc

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by