2021-04-09 13:36:06 +00:00
\documentclass { scrartcl}
\usepackage [utf8] { inputenc}
2021-04-09 14:29:32 +00:00
\usepackage { float}
2021-04-09 13:36:06 +00:00
\usepackage { graphicx}
\usepackage { subcaption}
\usepackage { amsmath}
\usepackage { pgfplots}
\pgfplotsset { compat=newest}
\usetikzlibrary { plotmarks}
\usetikzlibrary { arrows.meta}
\usepgfplotslibrary { patchplots}
\usepackage { grffile}
\usepackage { amsmath}
\usepackage { subcaption}
\usepgfplotslibrary { external}
\tikzexternalize
\usepackage [margin=2.5cm] { geometry}
% To compile:
% sed -i 's#title style={font=\\bfseries#title style={yshift=1ex, font=\\tiny\\bfseries#' *.tex
% luatex -enable-write18 -shellescape main.tex
\pgfplotsset { every x tick label/.append style={ font=\tiny , yshift=0.5ex} }
\pgfplotsset { every title/.append style={ font=\tiny , align=center} }
\pgfplotsset { every y tick label/.append style={ font=\tiny , xshift=0.5ex} }
\pgfplotsset { every z tick label/.append style={ font=\tiny , xshift=0.5ex} }
\setlength { \parindent } { 0cm}
\setlength { \parskip } { 0.5\baselineskip }
\title { Optimization methods -- Homework 2}
\author { Claudio Maggioni}
\begin { document}
\maketitle
\section { Exercise 1}
\subsection { Implement the matrix $ A $ and the vector $ b $ , for the moment, without taking into consideration the
boundary conditions. As you can see, the matrix $ A $ is not symmetric. Does an energy function of
the problem exist? Consider $ N = 4 $ and show your answer, explaining why it can or cannot exist.}
2021-04-10 10:39:47 +00:00
The implementation of a function that generates $ A $ w.r.t. the parameter $ N $ can be found in the MATLAB script
\texttt { main.m} under Section 1.1.
The matrix $ A $ and the vector $ b $ appear in the following form:
\[ A = \begin { bmatrix }
1 & 0 & 0 & 0 & \ldots & 0 \\
-1 & 2 & -1 & 0 & \ldots & 0 \\
0 & -1 & 2 & -1 & \ldots & 0 \\
\vdots & \vdots & \vdots & \vdots & \ddots & \vdots \\
0 & 0 & 0 & 0 & \ldots & 1 \\
\end { bmatrix} \; \; \; b = \begin { bmatrix} 0\\ h^ 2\\ h^ 2\\ \vdots \\ 0\end { bmatrix} \]
For $ N = 4 $ , we can attempt to build a minimizer to the solve the system $ Ax = b $ . In order to find an $ x $ such that $ Ax = b $ , we could define a minimizer $ \phi ( x ) $ such that:
\[ \phi ( x ) = \| b - Ax \| ^ 2 \]
Here $ \phi ( x ) = 0 $ would mean that $ x $ is an exact solution of the system $ Ax = b $ . We can then attempt to write such minimizer for $ N = 4 $ :
\[ \phi ( x ) = \| b - Ax \| ^ 2 = \left | \begin { bmatrix } 0 - x _ 1 \\ \frac 19 - x _ 1 + 2 x _ 2 - x _ 3 \\
\frac 19 -x_ 2 +2x_ 3 -x_ 4\\ 0 - x_ 4\end { bmatrix} \right |^ 2 =\] \[ = x _ 1 ^ 2 + \left ( \frac 19 - x _ 1 + 2 x _ 2 - x _ 3 \right ) ^ 2 + \left ( \frac 19 - x _ 2 + 2 x _ 3 - x _ 4 \right ) ^ 2 + x _ 4 ^ 2 \]
\[ \Delta \phi ( x ) = \begin { bmatrix } 4 x _ 1 - 4 x _ 2 + 2 x _ 3 - \frac 29 \\
-4x_ 1 +10x_ 2 -8x_ 3 + 2x_ 4 +\frac 29\\
2x_ 1 -8x_ 2 +10x_ 3 + -4x_ 4 +\frac 29\\
2x_ 2 - 4x_ 3 + 4x_ 4 -\frac 29\end { bmatrix} \; \; \; \Delta ^ 2 \phi (x) = \begin { bmatrix} 4& -4& 2& 0\\ -4& 10& -8& 2\\ 2& -8& 10& -4\\ 0& 2& -4& 4\end { bmatrix} \]
As it can be seen from the Hessian calculation, the Hessian is positive definite forall $ x $ s. This means, by the sufficient condition of minimizers, that we can find a minimizer by solving $ \Delta \phi ( x ) = 0 $ (i.e. finding stationary points in the hyperspace defined by $ \phi ( x ) $ . Solving that, we find:
\[ x = \begin { bmatrix } 0 \\ \frac 19 \\ \frac 19 \\ 0 \end { bmatrix } \; \; \]
which is indeed the minimizer and solution of $ Ax = b $ . Therefore, $ \phi ( x ) $ is a valid energy function and we can say an energy function for the problem exists.
2021-04-09 13:36:06 +00:00
\subsection { Once the new matrix has been derived, write the energy function related to the new problem
and the corresponding gradient and Hessian.}
2021-04-10 10:39:47 +00:00
As by the definitions of $ A $ and $ b $ given in the assignment, we already enforce $ x _ 1 = x _ n = 0 $ , since the first and the last term of the matrix-vector product $ Ax $ are $ x _ 1 $ and $ x _ n $ respectively and the system of equations represented by $ Ax = b $ would indeed include the equalities $ x _ 1 = b _ 1 = 0 $ and $ x _ n = b _ n = 0 $ . Therefore, we can simply alter the matrix $ A $ without any need to perform any other transformation in the system.
We therefore define $ \overline { A } $ as a copy of $ A $ where $ \overline { A } _ { 2 , 1 } = \overline { A } _ { n - 1 , n } = 0 $ .
2021-04-09 13:36:06 +00:00
2021-04-10 10:39:47 +00:00
The objective function then becomes $ \phi ( x ) = \frac 12 x ^ T \overline { A } x - b ^ T x $ .
And since the objective is a standard quadratic form, the gradient is $ \overline { A } x - b $ while the Hessian is $ \overline { A } $ .
2021-04-09 13:36:06 +00:00
\subsection { Write the Conjugate Gradient algorithm in the pdf and implement it Matlab code in a function
called \texttt { CGSolve} .}
See page 112 (133 for pdf) for the algorithm implementation
2021-04-10 10:39:47 +00:00
The solution of this task can be found in Section 1.3 of the script \texttt { main.m} under the function \texttt { CGSolve} .
2021-04-09 13:36:06 +00:00
\subsection { Solve the Poisson problem.}
The solution of this task can be found in Section 1.4 of the script \texttt { main.m} .
\subsection { Plot the value of energy function and the norm of the gradient (here,
use semilogy) as functions of the iterations.}
The solution of this task can be found in Section 1.5 of the script \texttt { main.m} .
2021-04-09 14:29:32 +00:00
\begin { figure} [H]
\begin { subfigure} { 0.5\textwidth }
\resizebox { \textwidth } { \textwidth } { \input { obvalues} }
\caption { Objective function values w.r.t. iteration number}
\end { subfigure}
\begin { subfigure} { 0.5\textwidth }
\resizebox { \textwidth } { \textwidth } { \input { gnorms} }
\caption { Norm of the gradient w.r.t. iteration number \\ (y-axis is log scaled)}
\end { subfigure}
\caption { Plots for Exercise 1.4.}
\end { figure}
2021-04-09 13:36:06 +00:00
\subsection { Finally, explain why the Conjugate Gradient method is a Krylov subspace method.}
Because theorem 5.3 holds, which itself holds mainly because of this (5.10, page 106 [127]):
\[ r _ { k + 1 } = r _ k + a _ k * A * p _ k \]
\section { Exercise 2}
Consider the linear system $ Ax = b $ , where the matrix $ A $ is constructed in three different ways:
\begin { itemize}
\item $ A = $ diag([1:10])
\item $ A = $ diag(ones(1,10))
\item $ A = $ diag([1, 1, 1, 3, 4, 5, 5, 5, 10, 10])
\item $ A = $ diag([1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0])
\end { itemize}
\subsection { How many distinct eigenvalues has each matrix?}
Each matrix has a distinct number of eigenvalues equal to the number of distinct
elements on its diagonal. So, in order, each A has respectively 10, 1, 5, and 10 distinct eigenvalues.
\subsection { Construct a right-hand side $ b = $ rand(10,1) and apply the
Conjugate Gradient method to solve the system for each $ A $ .}
The solution of this task can be found in section 2.2 of the \texttt { main.m} MATLAB script.
\subsection { Compute the logarithm energy norm of the error for each matrix
and plot it with respect to the number of iteration.}
The solution of this task can be found in section 2.3 of the \texttt { main.m} MATLAB script.
2021-04-09 14:29:32 +00:00
\begin { figure} [H]
\begin { subfigure} { 0.5\textwidth }
\resizebox { \textwidth } { !} { \input { a1} }
\caption { First matrix}
\end { subfigure}
\begin { subfigure} { 0.5\textwidth }
\resizebox { \textwidth } { !} { \input { a2} }
\caption { Second matrix}
\end { subfigure}
\begin { subfigure} { 0.5\textwidth }
\resizebox { \textwidth } { !} { \input { a3} }
\caption { Third matrix}
\end { subfigure}
\begin { subfigure} { 0.5\textwidth }
\resizebox { \textwidth } { !} { \input { a4} }
\caption { Fourth matrix}
\end { subfigure}
\caption { Plots of logarithm energy norm of the error per iteration. Minus infinity logarithms not shown in the plot.}
\end { figure}
2021-04-09 13:36:06 +00:00
\subsection { Comment on the convergence of the method for the different matrices. What can you say observing
the number of iterations obtained and the number of clusters of the eigenvalues of the related
matrix?}
The method converges quickly for each matrix. The fastest convergence surely happens for $ A 2 $ , which is
the identity matrix and therefore makes the $ Ax = b $ problem trivial.
For all the other matrices, we observe the energy norm of the error decreasing exponentially as the iterations
increase, eventually reaching $ 0 $ for the cases where the method converges exactly (namely on matrices $ A 1 $ and $ A 3 $ ).
Other than for the fourth matrix, the number of iterations is exactly equal
to the number of distinct eigenvalues for the matrix. That exception on the fourth matrix is simply due to the
tolerance termination condition holding true for an earlier iteration, i.e. we terminate early since we find an
approximation of $ x $ with residual norm below $ 10 ^ { - 8 } $ .
\end { document}