在MATLAB中计算对角分块矩阵的逆矩阵

3

我有一个类似这样的大矩阵M

M=[A1, Z,  Z,  Z,  Z,  Z ; 
   Z,  A2, Z,  Z,  Z,  Z ; 
   Z,  Z,  A3, Z,  Z,  Z ; 
   Z,  Z,  Z,  A4, Z,  Z ; 
   Z,  Z,  Z,  Z,  A5, Z ; 
   Z,  Z,  Z,  Z,  Z,  A6];

A = [A1,A2,A3,A4;A2,A5,A6,Z;A3,A6,Z,Z;A4,Z,Z,Z]

and then use the following formula to calculate the inverse matrix of A:

M = inv(A1) - inv(A1)*B*inv(B)*inv(A1)

where B = A5 - A2*inv(A1)*transpose(A2).

invM=[B1, Z,  Z,  Z,  Z,  Z 
      Z,  B2, Z,  Z,  Z,  Z 
      Z,  Z,  B3, Z,  Z,  Z 
      Z,  Z,  Z,  B4, Z,  Z 
      Z,  Z,  Z,  Z,  B5, Z 
      Z,  Z,  Z,  Z,  Z,  B6];
B1,B2,B3,B4,B5,B6A1,A2,A3,A4,A5,A6 的逆矩阵。但当有很多很多的 B 时,如何进行批处理呢?
谢谢您的提前帮助。

如果您拥有图像处理工具箱,您应该查看blockproc函数。 - Dan
1
你们的 A 矩阵实际上是如何存储的呢?M 是作为稀疏矩阵存储,还是只存储 A 块?所有的 A 矩阵都是唯一的吗? - horchler
2个回答

1
坦白说,我不会为反向操作烦恼。你可能根本不需要反向操作,而是需要 乘积
x(n) = inv(A(n))*b(n)

其中b是方程Ax = b中的解向量。

这个重要的原因在于:

clc

N = 4;    % Size of each A
m = 300;  % Amount of matrices

% Create sparse, block diagonal matrix, and a solution vector
C = cellfun(@(~)rand(4), cell(m,1), 'UniformOutput', false);
A = sparse(blkdiag(C{:}));
b = randn(m*N,1);


% Block processing: use inv()
tic
for ii = 1:1e3
    for jj = 1:m
        inds = (1:4) + 4*(jj-1);
        inv(A(inds,inds)) * b(inds); %#ok<MINV>
    end    
end
toc

% Block processing: use mldivide()
tic
for ii = 1:1e3
    for jj = 1:m
        inds = (1:4) + 4*(jj-1);
        A(inds,inds) \ b(inds);
    end
end
toc

% All in one go: use inv()
tic
for ii = 1:1e3
    inv(A)*b;
end
toc

% All in one go: use mldivide()
tic
for ii = 1:1e3
    A\b;
end
toc

结果:

Elapsed time is 4.740024 seconds.  % Block processing, with inv()
Elapsed time is 3.587495 seconds.  % Block processing, with mldivide()
Elapsed time is 69.482007 seconds. % All at once, with inv()
Elapsed time is 0.319414 seconds.  % All at once, with mldivide()

现在,我的电脑与大多数电脑有些不同,所以您可能需要重新进行此测试。但比率大致相同——计算显式逆需要的时间比计算乘积 x = inv(A)*b 多得多。
如果在使用mldivide时内存不足,则不应循环处理所有单独矩阵,而是将问题分解成较大的块。类似这样:
chunkSize = N*100;
x = zeros(size(A,1),1);
for ii = 1:N*m/chunkSize
    inds = (1:chunkSize) + chunkSize*(ii-1);
    x(inds) = A(inds,inds) \ b(inds);
end

0

4
但这是一个分块对角矩阵,每个A都是4x4的。事实上,OP在问题中已经提出了这个解决方案。它所问的是如何高效地计算这么多的逆矩阵。 - Dan
1
我的矩阵是分块对角线的,而不是对角线的。 - f. c.
循环有什么问题? - Luis Mendo
我有数百万个A。这需要太长时间了。 - f. c.
你可以看看分块三对角矩阵这一部分,也许会给你一些思路。否则你需要进行LU分解或类似的操作。 - Vuwox

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接