I don't have enough memory to simply create diagonal matrix D x D, getting an 'out of memory' error. Instead of performing M x D x D operations in the first multiplication, I do M x D operations, but still my code takes ages to run.
Can anybody find a more effective way to multiply these matrices in matlab?
D=20000 M=25 A = floor(rand(D,M)*10); B = floor(rand(1,M)*10); for i=1:D for j=1:M result(i,j) = A(i,j) * B(1,j); end end manual = result * A'; auto = A*diag(B)*A'; isequal(manual,auto)