mrdivide for sparse blockdiagonal matrices

2 次查看(过去 30 天)
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{:})

回答(1 个)

Fangjun Jiang
Fangjun Jiang 2011-9-3
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

类别

Help CenterFile Exchange 中查找有关 Language Fundamentals 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by