% (c) 2004/2005 Universitaet Stuttgart
% Chair 'Numerische Mathematik fuer Hoechstleistungsrechner'
% http://www.ians.uni-stuttgart.de/nmh
%
% ----------------------------------------------------------
% Permission to use this exercise for non-profit educational
% purposes is hereby granted provided that this copyright
% notice is included in all copies or substantial portions
% of the LaTeX files.
% ----------------------------------------------------------
\begin{exercise}{Preconditioned cg method}{tutorial}{10}{indir07\_eng}
\begin{itemize}
\item[\bf a)] Test Matlab's \texttt{pcg} method using the Poisson matrix $A$, obtained with the command\\
\centerline{\texttt{A = gallery('poisson', k)}}
for $k = 1, \ldots, 25$ and the right-hand side $(1,\ldots,1)^T$. Let \texttt{tol} = 1e-4, \texttt{maxit} = 200, and call the method in the form\\
\centerline{\texttt{[x, flag, res, iter] = pcg(A, b, tol, maxit, W)}.}
Use the following preconditioners: $W_I = I$, $W_J = D$, $W_{SGS} = (D+L)D^{-1}(D+L^T)$, and $W_{SSOR} = \frac{1}{2-\omega}(\frac 1\omega D + L)(\frac 1\omega D)^{-1} (\frac 1\omega D + L^T)$ with $\omega = 1.5$. Plot the number of required iterations w.r.t. the number of unknowns in semi-logarithmic scale using \texttt{semilogx}.
\item[\bf b)] In each step, the residual vector $r' = W^{-1}r$ must be computed with respect to the preconditioned system. Matlab offers the option to pass the positive definite preconditioner $W$ in splitted form, i.e. $W = W_1W_2$. Explain why passing $W$ in suitably decomposed form offers significant computational advantages. Verify this by calling $\texttt{pcg}$ with the alternative syntax \texttt{pcg(A, b, tol , maxit, W1, W2)}, and compare the performance of \texttt{pcg} using \texttt{tic} and \texttt{toc} with the calling syntax of {\bf a)}.
\end{itemize}
\end{exercise}