如何将 GMRES 用于矩阵而不是向量?

How to use GMRES to Matrices rather then vectors?

GMRES算法及其matlab实现应该求解线性方程组,例如

%Ax = b
A = rand(4);
b = rand(4,1);
x = gmres(A,b);

也可以使用函数句柄 foo = @(x) A*x + conj(A)*5*x; y = gmres(foo,b);

我要的是解决以下问题

B = rand(4);
H = rand(4);
foo2 = H*B + B*H;
X = gmres(foo2, B) %Will not run!
--Error using gmres (line 94)
--Right hand side must be a column vector of length 30 to match the coefficient matrix.

从数学上讲,我不明白为什么 gmres 也不能应用于这个问题。

注意:我真正想解决的是 PDE dB/dt = B_xx + B_yy 的隐式欧拉方法,所以 H 实际上是第二个使用有限差分的导数矩阵。

谢谢 阿米尔

如果我没理解错的话,您想使用 GMRES 来求解一个 sylvester equation

A*X + X*A = C

对于 n×n 矩阵 AXC。 (我问了一个related question yesterday over at SciComp and got this great answer。)

要使用 GMRES,您可以将此矩阵-矩阵方程表示为大小 n^2 矩阵-向量方程。为方便起见,我们可以使用 Kronecker product, implemented in MATLAB with kron:

A = randn(5);
X = randi(3,[5 5]);

C = A*X + X*A;

% Use the Kronecker product to form an n^2-by-n^2 matrix
%            A*X       +        X*A
bigA = (kron(eye(5),A) + kron(A.',eye(5)));

% Quick check that we're getting the same answer
norm(bigA*X(:) - C(:))

% Use GMRES to calculate X from A and C.
vec_X_gmres = gmres(bigA,C(:));
X_gmres = reshape(vec_X_gmres,5,5);