![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/237671/image.png)
Fast computation of an equation.
2 ビュー (過去 30 日間)
古いコメントを表示
David Ernesto Caro
2019 年 9 月 9 日
コメント済み: David Ernesto Caro
2019 年 9 月 11 日
Given two matrices:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/237668/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/237688/image.png)
We want a the fastest way to compute the vector \phi.... (j=1 to m).
Is there a way to use parallel computation, any trick?
8 件のコメント
Bruno Luong
2019 年 9 月 10 日
編集済み: Bruno Luong
2019 年 9 月 10 日
what are typically m,n and s?
If you have X as matrix the best method might be different, see my answer bellow.
採用された回答
Bruno Luong
2019 年 9 月 10 日
編集済み: Bruno Luong
2019 年 9 月 10 日
The efficientcy of the bellow method depend on m, n, s
% Generate dummy test data
m = 1000;
n = 1000;
s = 1000;
W = rand(m,n);
V = rand(m,n);
X = rand(n,s);
% Walter method
tic
Xp = permute(X,[3 1 2]);
Z1 = sum((Xp-W).*(V-Xp),2);
Z1 = reshape(Z1,[m s]).';
toc % Elapsed time is 2.816333 seconds.
% My new method
tic
Z2 = -sum(X.^2,1)+(W+V)*X-sum(W.*V,2);
Z2 = Z2.';
toc % Elapsed time is 0.040274 seconds.
% Check correctness
norm(Z1-Z2,'fro')/norm(Z1,'fro') % 4.6622e-15
その他の回答 (0 件)
参考
カテゴリ
Help Center および 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!