Multiplication of very large matrix
4 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
Could anyone help me in re-writing the following equation to make the processing faster. N here is the number of points and it could be 50,000. D is a diagonal matrix where only the diagonal contains values and the other elements are zeros.
M=eye(N)-((1./max((ones(N)'*D*ones(N)),eps))*(ones(N)*ones(N)'*D));
采纳的回答
Jan
2020-12-14
编辑:Jan
2020-12-14
How strange: The comments above have not been displayed on my other computer. So this answer was written 1 hour after MA's comment.
In ones(N)*ones(N)' the transposition is completely meaningless. The result can be obtained much cheaper by: repmat(N, [N, N]). The matrox multiplication with this matrix can be formulated much cheaper:
The multiplication by () is an extremly expensive way to calculate:
A = ones(N) * ones(N)' * D
B = sum(D, 1) * N
Now B is a row vector only, but A is only a blownup version with N repetitions.
Because D is a diagonal matrix, you can omit the sum also.
Equivalently for ones(N)'*D*ones(N) : Of course you cannot simply omit the multiplication, but you can express it much cheaper by: sum(D(:)) or cheaper: sum(diag(D)) .
DD = diag(D);
M = eye(N) - N^2 * DD.' ./ max(sum(DD), eps);
Note, that this matrix is extremely redundant: All columns contain the same value except for the diagonal, which is 1 smaller. An efficient implementation would exploit this instead of creating a large matrix.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!