Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Why is this Matrix Multiplication taking so long... using diag function

2 ビュー (過去 30 日間)
daniel adams
daniel adams 2021 年 11 月 12 日
閉鎖済み: daniel adams 2021 年 11 月 12 日
Hi the vectors are of length , and an array K is of length I want to turn into diagonal arrays to calculate the product and then sum the columns of this product, my code is
a=diag(a);
b=diag(b);
op=a*K*b;
p=sum(op);
but it takes a really long time to run, am I doing something that is bad practice which is slowing down this procedure im confused why this should take so long? More specifically the run time for that bit of code is 45 seconds !
EDIT : Consider the code
m=10000 % or something larger !
K=rand(m);
a=rand(m,1);
b=rand(m,1);
% I want to calculate the matrix which has component i,j $a_i K_(i,j) b_j $
% and then sum the columns of the resulting matrix.
% The following code is how I did this but it takes 45 seconds to run, is
% there a faster method ?
tic
a=diag(a);
b=diag(b);
op=a*K*b;
p=sum(op);
toc

回答 (0 件)

この質問は閉じられています。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by