Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我有两个矩阵A和B,那么执行以下操作(在 Matlab 中)的最佳方法是什么,让我们说两者的大小m-by- n:
A
B
m
n
C = zeros(m,m); for t=1:n C=C+A(:,t)*B(:,t)'; end
这无非就是
C = A*B';
在哪里,A并且B是每个m-by- n。除非矩阵具有特殊属性,否则我不确定您是否会比这更有效率。
bsxfun当维度足够大(可能是 100×100 或更大)并且一个矩阵是对角线时,您可能会从使用矩阵乘法中受益的一个地方,例如:
bsxfun
A = rand(1e2); B = diag(rand(1,1e2)); C = bsxfun(@times,A,diag(B).');
这发生在许多矩阵变换中——参见sqrtm例如 ( edit sqrtm) 的代码。
sqrtm
edit sqrtm