필터 지우기
필터 지우기

mrdivide for sparse blockdiagonal matrices

조회 수: 2 (최근 30일)
Frank
Frank 2011년 9월 2일
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