Borrar filtros
Borrar filtros

mrdivide for sparse blockdiagonal matrices

2 visualizaciones (últimos 30 días)
Frank
Frank el 2 de Sept. de 2011
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{:})

Respuestas (1)

Fangjun Jiang
Fangjun Jiang el 3 de Sept. de 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

Categorías

Más información sobre Language Fundamentals en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by