Last week, I have learned the details of the robust iterative methods of PCG, MINRES, GMRES, which will converges to the exact solution $x^*$ of nonsingular system within $N$ steps for $A\in \mathbb{R}^{N\times N}$: $$ Ax=b. $$ And the requirements for the matrix is: SPD matrix for PCG, symmetric matrix for MINRES, nonsymmetric matrix for GMRES. The reason is that these 3 above methods are optimal, i.e., their residual vectors are mutually orthogonal, so their residual vectors, e.g., $r_0,r_1,...,r_N$ must satisfy $r_N=0$, which produces the exact solution in the $N$-th step. So, I have done some examples in matlab (matlab 2018b, 8GB win10 OS environment) as follows:
clc;clear;
rng(0);% to fix the rand number
n=10;
A=rand(n); % generate a nonsingular matrix
b=rand(n,1);
% for general matrix
gmres(A,b);
%% for SPD matrix
pcg(A*A',b);
minres(A*A',b);
gmres(A*A',b);
And the results are:
gmres converged at iteration 10 to a solution with relative residual 0.
pcg stopped at iteration 10 without converging to the desired tolerance 1e-06
because the maximum number of iterations was reached.
The iterate returned (number 10) has relative residual 0.02.
minres stopped at iteration 10 without converging to the desired tolerance 1e-06
because the maximum number of iterations was reached.
The iterate returned (number 10) has relative residual 0.016.
gmres converged at iteration 10 to a solution with relative residual 0.
It is so strange that gmres is normal for both nonsymmetric and SPD matrix but pcg and minres are abnormal. Because matrix $AA^T$ is SPD, then in theory, pcg and minres must converge in N steps, but they fail. Does it mean that we should use GMRES as much as possible instead of other methods regardless of the SPD matrix or else, because gmres command is so robust for nonsymmetric and SPD matrix? Is anything wrong? any suggestions?