Speeding up matrix exponentials
古いコメントを表示
Hey all,
I am trying to speed up the calculation of matrix exponentials but the process is not fast enough and I cannot think of a more efficient way (without using parfor). The code is:
a = diag(ones(1,999),1) + diag(-ones(1,999),-1);
b = expm(a);
c = [];
counter = 1; %keep track of progress of for loop%
for i = 1:10^4-1
factor = exp(1j*(i+1)) - exp(1j*i);
c = [c,b^factor];
counter
counter = counter+1;
end
This process takes too long for 10^4 iterations so I was hoping there was a faster method, maybe some kind of vectorization or something?
Thanks
7 件のコメント
Rik
2023 年 4 月 4 日
Since you don't do anything with the result, you can simply do the last and skip the rest.
I also suspect a lot of time is being spent printing the counter.
Can you confirm you need a matrix exponentiation instead of an element-wise exponent?
per isakson
2023 年 4 月 4 日
bil
2023 年 4 月 4 日
Is it necessary to display or print the counter (which can be done with the loop index btw) ?
Pre-allocation is difficult with this one, as it requires too much memory (~74.5 GB of RAM). And that brings us to the fact that you will probably not have enough memory to store the final output as well.
Although, you can pre-allocate a cell array to store the data, even then it's still a question of memory.
As for speed, the bottle neck seems to calculating b^fact (not the loop).
I suggest you to find an effecient method to calculate matrix power. I was unable to find something from a cursory glance on FEX.
a = diag(ones(1,999),1) + diag(-ones(1,999),-1);
b = expm(a);
c = cell(10,1);
%counter = 1; %keep track of progress of for loop%
tic
for k = 1:10-1
fact = exp(1j*(k+1)) - exp(1j*k);
c{k} = b^fact;
end
toc
~12 seconds for 10 iterations
bil
2023 年 4 月 4 日
Mike Croucher
2023 年 4 月 4 日
編集済み: Mike Croucher
2023 年 4 月 4 日
Can you talk about your application any more? Some questions I have include
- Would single precision be good enough for you?
- There is no pagempower function. But if there were would it have helped you? If so, a bit more info about your application would be really useful.
- Why can't you use parfor?
- What hardware do you have access to? HPC cluster? GPU?
bil
2023 年 4 月 4 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!