Lecture 23

advertisement
Lecture 23
Solve Ax = d: Generalized Minimum Residual Method
(Lecture notes taken by Zhibin Deng and Xiaoyin Ji)
ο‚·
Comparison of Block Tri-diagonal (BT), Conjugate Gradient (CG) and
Generalized Minimum Residual (GMRES)
Table 1: Algorithm Comparison
nx=ny=nz
L_2 Error
6
11
21
41
4.9582
1.2461
0.3120
0.0782
Compute Time (seconds)
BT
CG
GMRES
1.6104
93.2287
2.8129
207.0849
2.9496
??
The result is obtained in MATLAB 2010, Core i-7-920.
Remark:
1. Block Tri-diagonal Algorithm requires the matrix form is block tri-diagonal.
However, there are less linear solvers in it, hence the compute time is less. This
method is efficient if the matrix is sparse.
2. Conjugate Gradient method requires the matrix form is symmetric positive definite.
It only needs to store the last direction.
3. GMRES has no special requirement in matrix form, however, it has to store all
directions in the process.
ο‚·
Krylov Space.
Definition: Subspace 𝒦m+1 spanned by vectors {π‘Ÿ 0 , π΄π‘Ÿ 0 , 𝐴2 π‘Ÿ 0 , 𝐴3 π‘Ÿ 0 , … , π΄π‘š π‘Ÿ 0 } is called
Krylov space, where π‘Ÿ 0 = 𝑑 − 𝐴π‘₯ 0 is an initial vector.
Note that 𝐴π‘₯ = 𝑑 ⇔ π‘Ÿ(π‘₯) = 𝑑 − 𝐴π‘₯ = 0 ⇔ π‘šπ‘–π‘›π‘¦ π‘Ÿ 𝑇 (𝑦)π‘Ÿ(𝑦) = 0
The main idea of GMRES algorithm is to approximate the solution of system 𝐴π‘₯ = 𝑑 by a
linear combination of Krylov vectors 𝐴𝑖 π‘Ÿ 0. Define π‘₯ π‘š+1 = π‘₯ 0 + 𝛼0 π‘Ÿ 0 + 𝛼1 π΄π‘Ÿ 0 + β‹― +
π›Όπ‘š π΄π‘š π‘Ÿ 0. We need to find 𝛼 = (𝛼0 , … , π›Όπ‘š ) such that π‘Ÿ 𝑇 (π‘₯ π‘š+1 )π‘Ÿ(π‘₯ π‘š+1 ) is minimized.
𝑖 0
Let 𝑦 = π‘₯ 0 + π’¦π‘š+1 , and 𝒦m+1 = {𝑧|𝑧 = ∑π‘š
𝑖=0 𝛼𝑖 𝐴 π‘Ÿ }, then
π‘Ÿ 𝑇 (π‘₯ π‘š+1 )π‘Ÿ(π‘₯ π‘š+1 ) = π‘šπ‘–π‘›π‘¦∈π‘₯ 0 +π’¦π‘š+1 π‘Ÿ 𝑇 (𝑦)π‘Ÿ(𝑦)
Note:
π‘Ÿ(π‘₯ π‘š+1 ) = 𝑑 − 𝐴π‘₯ π‘š+1
= 𝑑 − 𝐴(π‘₯ 0 + 𝛼0 π‘Ÿ 0 + 𝛼1 π΄π‘Ÿ 0 + β‹― + π›Όπ‘š π΄π‘š π‘Ÿ 0 )
= [𝐼 − (𝛼0 𝐴 + 𝛼1 𝐴2 + β‹― + π›Όπ‘š π΄π‘š+1 )]π‘Ÿ 0.
Let π‘žπ‘š+1 (𝐴) = 𝐼 − (𝛼0 𝐴 + 𝛼1 𝐴2 + β‹― + π›Όπ‘š π΄π‘š+1 ), which is polynomial of matrix 𝐴.
When matrix 𝐴 is invertible and π‘š = 𝑛 − 1, consider matrix 𝐴’s characteristic polynomial.
Then, 𝑓(𝐴) = 0, and we have a solution r(x) = 0. However, generally we have π‘š β‰ͺ 𝑛 when
algorithm terminates.
ο‚·
Hessenburg matrix.
--efficient method for finding 𝛼
𝑛×π‘š
⏞ = [π΄π‘Ÿ 0 , … , π΄π‘š−1 π‘Ÿ 0 ]
𝕂
𝑛×𝑛 𝑛×π‘š π‘š×1
𝑛×1
⏞ 𝕂
⏞
𝐴
𝛼 = π‘Ÿβž0 , 𝛼 ∈ β„π‘š , 𝑛 ≫ π‘š
π‘š ⏞
π‘₯ π‘š = π‘₯ 0 + π•‚π‘š
This is a LS (least square) problem. We use QR to solve the normal equation. In order to deal
with that, we replace π•‚π‘š by π•π‘š , whose columns 𝑣𝑗 s are orthogonal. For example,
Col 1: π‘Ÿ 0 = 𝑏𝑣1
𝑣1 𝑇 𝑣1 = 1
𝑇
𝑏 = √π‘Ÿ 0 π‘Ÿ 0
𝑣1 = π‘Ÿ 0 /𝑏
Col. 2: 𝐴𝒦1 ⊂ 𝒦2
𝐴𝑣1 = 𝑣1 β„Ž11 + 𝑣2 β„Ž21
𝑣1 𝑇 𝐴𝑣1 = 𝑣1 𝑇 𝑣1 β„Ž11 + 𝑣1 𝑇 𝑣2 β„Ž21 = β„Ž11
𝑧 = 𝐴𝑣1 − 𝑣1 β„Ž11 = 𝑣2 β„Ž21 , and note 𝑣2 𝑇 𝑣2 = 1
2
𝑧 𝑇 𝑧 = β„Ž21
β„Ž21 = √𝑧 𝑇 𝑧
𝑣2 = 𝑧/β„Ž21
𝐴[𝑣1 ] = [𝑣1
𝑣2 ] [β„Ž11 ]
β„Ž21
Col. 3: 𝐴𝒦 ⊂ 𝒦3
𝐴𝑣2 = 𝑣1 β„Ž12 + 𝑣2 β„Ž22 + 𝑣3 β„Ž32
𝐴[𝑣1
𝑣2 ] = ⏟
[𝑣1
𝑣2
β„Ž11
𝑣3 ] [β„Ž21
𝑛×3
⏟
β„Ž12
β„Ž22 ]
β„Ž32
3×2
...
𝐴[𝑣1
β‹― π‘£π‘š ] = [𝑣1
β‹―
π‘£π‘š
β‹±
π‘£π‘š+1 ] [ β‹±
⏟
β‹±
β‹±
]
β‹±
π‘š+1×π‘š π»π‘’π‘ π‘ π‘’π‘›π‘π‘’π‘Ÿπ‘”
Reduction Theorem: The following are equivalent
1. LS problem π΄π•‚π‘š 𝛼 = π‘Ÿ 0 has solution π‘₯ π‘š+1 = π•‚π‘š 𝛼 + π‘₯ 0
2. LS problem π΄π•π‘š 𝛽 = π•π‘š+1 𝑒1 𝑏 has solution π‘₯ π‘š+1 = π•π‘š 𝛽 + π‘₯ 0
3. LS problem 𝐻𝛽 = 𝑒1 𝑏 has solution π‘₯ π‘š+1 = π•π‘š 𝛽 + π‘₯ 0
Note that we need matrix π•π‘š to compute new iteration solution π‘₯ π‘š+1 , that’s why we have to
store all the directions 𝑣j .
ο‚·
Givens transforms and QR factors.
According to Reduction Theorem, we convert the LS problem π΄π•‚π‘š 𝛼 = π‘Ÿ 0 into a new LS
problem 𝐻𝛽 = 𝑒1 𝑏. Note that 𝐻 is a Hessenberg matrix, we can use Givens rotations to solve the
new LS problem easily if π‘š β‰ͺ 𝑛.
ο‚·
GMRES algorithm.
𝑇
Choose initial guess π‘₯ 0 , let π‘Ÿ 0 = 𝑑 − 𝐴π‘₯ 0 , 𝑏 = √π‘Ÿ 0 π‘Ÿ 0 , 𝑉(: ,1) = π‘Ÿ 0 /𝑏,
for k = 1 to maxm
𝑉(: , π‘˜ + 1) = 𝐴𝑉(: , π‘˜)
Compute the columns of 𝑉(: , π‘˜ + 1) π‘Žπ‘›π‘‘ 𝐻(: , π‘˜ + 1)
Compute the QR factors of H
Test for convergence
end
π‘₯ π‘˜+1 = π‘₯ 0 + 𝑉𝛽
gmresfull.m Code:
clear;
% Solves a block tridiagonal non SPD from the finite difference method of
%
- u_xx - u_yy + a1 u_x + a2 u_y + c u = f(x,y)
% with zero boundary conditions.
% Uses the generalized minimum residual method.
% Define the NxN coefficient matrix AA where N = n^2.
n = 10; N = n*n;
errtol = 0.001;
kmax = 200;
A = zeros(n); a1 = 10; a2 = 1; c = 1; h = 1./(n+1);
for i = 1:n
A(i,i) = 4 + c*h*h + a1*h + a2*h;
if (i>1)
A(i,i-1) = -1 - a1*h ;
end
if (i<n)
A(i,i+1) = -1;
end
end
I = eye(n);
II = I + I*a2*h;
AA = zeros(N);
for i = 1:n
newi = (i-1)*n + 1;
lasti = i*n;
AA(newi:lasti,newi:lasti) = A;
if (i>1)
AA(newi:lasti,newi-n:lasti-n) = -II;
end
if (i<n)
AA(newi:lasti,newi+n:lasti+n) = -I;
end
end
u = zeros(N,1);
r = zeros(N,1);
for j = 1:n
for i = 1:n
I = (j-1)*n + i;
r(I)= h*h*2000*(1+sin(pi*(i-1)*h)*sin(pi*(j-1)*h));
end
end
rho = (r'*r)^.5;
errtol = errtol*rho;
g = rho*eye(kmax+1,1);
v(:,1) = r/rho;
k = 0;
% Begin gmres loop.
while((rho > errtol) & (k < kmax))
k = k+1;
% Matrix vector product.
v(:,k+1) = AA*v(:,k);
% Begin modified GS. May need to reorthogonalize.
for j = 1:k
h(j,k) = v(:,j)'*v(:,k+1);
v(:,k+1) = v(:,k+1) - h(j,k)*v(:,j);
end
h(k+1,k) = (v(:,k+1)'*v(:,k+1))^.5;
if (h(k+1,k) ~= 0)
v(:,k+1) = v(:,k+1)/h(k+1,k);
end
% Apply old Givens rotations to h(1:k,k).
if k>1
for i=1:k-1
hik
= c(i)*h(i,k)-s(i)*h(i+1,k);
hipk
= s(i)*h(i,k)+c(i)*h(i+1,k);
h(i,k)
= hik;
h(i+1,k)
= hipk;
end
end
normh = norm(h(k:k+1,k));
% May need better Givens implementation.
% Define and apply new Givens rotations to h(k:k+1,k).
if normh ~= 0
c(k)
= h(k,k)/normh;
s(k)
= -h(k+1,k)/normh;
h(k,k)
= c(k)*h(k,k) - s(k)*h(k+1,k);
h(k+1,k)
= 0;
gk
= c(k)*g(k) - s(k)*g(k+1);
gkp
= s(k)*g(k) + c(k)*g(k+1);
g(k)
= gk;
g(k+1)
= gkp;
end
rho = abs(g(k+1));
mag(k) = rho;
end
% End of gmres loop.
% h(1:k,1:k) is upper triangular matrix in QR.
y = h(1:k,1:k)\g(1:k);
% Form linear combination.
for i = 1:k
u(:) = u(:) + v(:,i)*y(i);
end
k
figure(1)
semilogy(mag)
for j = 1:n
for i = 1:n
I = (j-1)*n + i;
u2d(i,j) = u(I);
end
end
figure(2)
uu2d = zeros(n+2);
uu2d(2:n+1,2:n+1) = u2d;
mesh(uu2d)
Download