mrdivide for sparse blockdiagonal matrices
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
when computing A/B where A and B are sparse block diagonal and have the same block structure, does it matter in terms of computation time whether to:
1. construct A and B as sparse matrices, and then compute C=A/B 2. for each block i, compute C_i=A_i/B_i, store them in a cell Ccell, and then define C=blkdiag(Ccell{:})
0 Commenti
Risposte (1)
Fangjun Jiang
il 3 Set 2011
I don't know. You could write a test to find out. From the code below, it seems that as N grows, approach 2 is faster.
N=20;
a=cell(N,1);
b=cell(N,1);
for k=1:N
a{k}=rand(k);
b{k}=rand(k);
end
t1=0;t2=0;
for k=1:100
tic;
A=blkdiag(a{:});
B=blkdiag(b{:});
C=A/B;
t1=t1+toc;
tic;
d=cell(N,1);
for j=1:N
d{j}=a{j}/b{j};
end
D=blkdiag(d{:});
t2=t2+toc;
end
fprintf('time for approach 1: %f\n',t1);
fprintf('time for approach 2: %f\n',t2);
time for approach 1: 0.503683
time for approach 2: 0.129935
0 Commenti
Vedere anche
Categorie
Scopri di più su Language Fundamentals in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!