21.06.2014 Views

Numerical Methods Contents - SAM

Numerical Methods Contents - SAM

Numerical Methods Contents - SAM

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Idea: Solve Ax = b approximately in two stages:<br />

➀ Approximation A −1 ≈ tril(A) (lower triangular part): ˜x = tril(A) −1 b<br />

➁ Approximation A −1 ≈ triu(A) (upper triangular part) and use this to approximately “solve” the<br />

error equation A(x − ˜x) = r, with residual r := b − A˜x:<br />

x = ˜x +triu(A) −1 (b − A˜x) .<br />

7 i f ( i == 1) , p = y ; rho0 = rho ;<br />

8 e l s e i f ( rho < rho0∗ t o l ) , return ;<br />

9 else beta = rho / rho_old ; p = y+beta∗p ; end<br />

10 q = evalA ( p ) ; alpha = rho / ( p ’ ∗ q ) ;<br />

11 x = x + alpha ∗ p ;<br />

12 r = r − alpha ∗ q ;<br />

13 i f ( nargout > 2) , xk = [ xk , x ] ; end<br />

14 end<br />

With L A := tril(A), U A := triu(A) one finds<br />

10 5 # (P)CG step<br />

10 5 # (P)CG step<br />

x = (L −1<br />

A + U−1 A − U−1 A AL−1 A )b ➤<br />

More complicated preconditioning strategies:<br />

Incomplete Cholesky factorization, MATLAB-ichol<br />

Sparse approximate inverse preconditioner (SPAI)<br />

B−1 = L −1<br />

A + U−1 A − U−1 A AL−1 A .<br />

✸<br />

Ôº¿ º¿<br />

A−norm of error<br />

10 0<br />

10 −5<br />

10 −10<br />

10 −15<br />

10 −20<br />

CG, n = 50<br />

CG, n = 100<br />

10 −25<br />

CG, n = 200<br />

PCG, n = 50<br />

PCG, n = 100<br />

PCG, n = 200<br />

10 −30<br />

0 2 4 6 8 10 12 14 16 18 20<br />

Fig. 52<br />

B −1 −norm of residuals<br />

10 0<br />

10 −5<br />

10 −10<br />

10 −15<br />

CG, n = 50<br />

10 −20<br />

CG, n = 100<br />

CG, n = 200<br />

PCG, n = 50<br />

PCG, n = 100<br />

PCG, n = 200<br />

10 −25<br />

0 2 4 6 8 10 12 14 16 18 20<br />

Fig. 53<br />

Ôº¿ º¿<br />

Example 4.3.4 (Tridiagonal preconditioning).<br />

Efficacy of preconditioning of sparse LSE with tridiagonal part:<br />

Code 4.3.5: LSE for Ex. 4.3.4<br />

1 A = spdiags ( repmat ( [ 1 / n, −1 ,2+2/n, −1 ,1/n ] , n , 1 ) ,[−n/2 , −1 ,0 ,1 ,n / 2 ] , n , n ) ;<br />

2 b = ones ( n , 1 ) ; x0 = ones ( n , 1 ) ; t o l = 1.0E−4; maxit = 1000;<br />

3 evalA = @( x ) A∗x ;<br />

4<br />

5 % no preconditioning<br />

6 invB = @( x ) x ; [ x , rn ] = pcgbase ( evalA , b , t o l , maxit , invB , x0 ) ;<br />

7<br />

8 % tridiagonal preconditioning<br />

9 B = spdiags ( spdiags (A,[ − 1 ,0 ,1]) ,[ −1 ,0 ,1] ,n , n ) ;<br />

10 invB = @( x ) B \ x ; [ x , rnpc ] = pcgbase ( evalA , b , t o l , maxit , invB , x0 ) ;<br />

n # CG steps # PCG steps<br />

16 8 3<br />

32 16 3<br />

64 25 4<br />

128 38 4<br />

256 66 4<br />

512 106 4<br />

1024 149 4<br />

2048 211 4<br />

4096 298 3<br />

8192 421 3<br />

16384 595 3<br />

32768 841 3<br />

# (P)CG step<br />

PCG iterations: tolerance = 0.0001<br />

CG<br />

PCG<br />

10 2<br />

10 1<br />

10 0<br />

10 1 10 2 10 3 10 4 10 5<br />

n<br />

Fig. 54<br />

10 3<br />

Clearly in this example the tridiagonal part of the matrix is dominant for large n.<br />

condition number grows ∼ n 2 as is revealed by a closer inspection of the spectrum.<br />

In addition, its<br />

Code 4.3.6: simple PCG implementation<br />

1 function [ x , rn , xk ] = pcgbase ( evalA , b , t o l , maxit , invB , x )<br />

2 r = b − evalA ( x ) ; rho = 1 ; rn = [ ] ;<br />

3 i f ( nargout > 2) , xk = x ; end<br />

4 for i = 1 : maxit<br />

5 y = invB ( r ) ;<br />

6 rho_old = rho ; rho = r ’ ∗ y ; rn = [ rn , rho ] ;<br />

Ôº¿ º¿<br />

Preconditioning with the tridiagonal part manages to suppress this growth of the condition number of<br />

B −1 A and ensures fast convergence of the preconditioned CG method.<br />

Ôº¿¼ º¿<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!