How to perform a sum over matrices in several dimensions?
Show older comments
Hello I have a rather large sum that I want to evaluate in MATLAB. Symbolically it looks like this:
huge_sum(qx,qy)=sum_n(sum_m(sum_kx(sum_ky(sum_i(sum_j( M1(n,m,kx,ky)*M2(n,kx,ky,i,j)*M3(m,kx+qx,ky+qy,i,j)*M4(qx,qy,i,j)
) ) ) ) ) ),
where each of the M's is a matrix. The indices run from 1 to
qx,qy,kx,ky: 25
i,j,m,n: 16
My current implementation is rather slow; it's simply a bunch of nested for loops, defining a matrix,M5(m,n,kx,ky,i,j), which I then sum for each value of qx.
The problem is that this code will take around 100 days to run, which is of course too much! Can anyone suggest a smarter way to do this?
5 Comments
Matt J
on 13 Jan 2014
Is there any sparsity in these arrays at all?
Henrik
on 13 Jan 2014
Are the matrices calculated in the same loop? I mean, the most time consuming step is most likely to calculate the matrix M5, is it possible to perform the matrix calculations in another way? I am not really sure of how you want to calculate the matrix. Are there any way to clarify that?
Walter Roberson
on 13 Jan 2014
Do some factoring. Your M1 and M2 indices are independent of qx and qy, so you can calculate the M1 * M2 part independently.
Henrik
on 13 Jan 2014
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!