% (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}{Implementation cg method}{tutorial}{10}{indir06\_eng} \begin{minipage}[t]{0.38\textwidth} \textit{cg algorithm:} \begin{itemize} \item Initialize:\$-5mm] \begin{itemize} \item[] Let u_0 be a start vector \item[] r^0 = f - Au^0 \item[] p^1 = r^0 \item[] \rho^0 = < r^0, r^0 > \end{itemize} \item Iteration: k = 1, 2, \ldots\\[-5mm] \begin{itemize} \item[] a^k = A \cdot p^k \item[] \alpha_k = \rho^{k-1}/< a^k, p^k > \item[] u^k = u^{k-1} + \alpha_k p^k \item[] r^k = r^{k-1} - \alpha_k a^k \item[] \rho^k = < r^k, r^k > \item[] p^{k+1} = r^k + \frac{\rho^k}{\rho^{k-1}} \cdot p^k \end{itemize} \end{itemize} \end{minipage}\hfill \begin{minipage}[t]{0.58\textwidth} Write a Matlab function with the function header \begin{verbatim} function [u,m] = solveCG(A, f, s, tol, max) \end{verbatim} that solves the linear equation system Au=f iteratively by using the cg algorithm (A must be a symmetric, positive definite n \times n matrix). \texttt{tol} represents a given termination condition (see below), \texttt{maxit} is the maximum number of iterations to perform, s is the iteration start vector. The output arguments of the function are the number of iterations performed m and the approximate solution vector u. \[ \text{Termination condition:} ~~ \frac{\norm{f-Au}_2}{\norm{f}_2} \leq \texttt{tol}$ Test your implemenation by solving $Ax=b$, $A$ the Poisson matrix, $b = (1,\ldots,1)^T$. \end{minipage} \end{exercise}