%\documentclass[12pt]{article}
\documentclass{article}
\usepackage{amsmath,amsthm,amssymb}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
 \usepackage{graphicx}
 \usepackage{listings}
 \usepackage{xcolor}
\usepackage{fancyhdr}

\pagestyle{fancy}
\fancyhf{}
\rhead{David Dobor}
\lhead{Recitation 1, Linear Algebra }
\rfoot{Page \thepage}



\definecolor{mygreen}{rgb}{0,0.6,0}
\definecolor{mygray}{rgb}{0.5,0.5,0.5}
\definecolor{mymauve}{rgb}{0.58,0,0.82}

\begin{document}
\lstset{ %
  backgroundcolor=\color{white},   % choose the background color; you must add \usepackage{color} or \usepackage{xcolor}
  basicstyle=\footnotesize,        % the size of the fonts that are used for the code
  breakatwhitespace=false,         % sets if automatic breaks should only happen at whitespace
  breaklines=true,                 % sets automatic line breaking
  captionpos=b,                    % sets the caption-position to bottom
  commentstyle=\color{mygreen},    % comment style
  deletekeywords={...},            % if you want to delete keywords from the given language
  escapeinside={\%*}{*)},          % if you want to add LaTeX within your code
  extendedchars=true,              % lets you use non-ASCII characters; for 8-bits encodings only, does not work with UTF-8
  %frame=single,                    % adds a frame around the code
  keepspaces=true,                 % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible)
  keywordstyle=\color{blue},       % keyword style
  language=Matlab,                 % the language of the code
  morekeywords={*,...},            % if you want to add more keywords to the set
  numbers=none,                    % where to put the line-numbers; possible values are (none, left, right)
  numbersep=5pt,                   % how far the line-numbers are from the code
  numberstyle=\tiny\color{mygray}, % the style that is used for the line-numbers
  rulecolor=\color{black},         % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. comments (green here))
  showspaces=false,                % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'
  showstringspaces=false,          % underline spaces within strings only
  showtabs=false,                  % show tabs within strings adding particular underscores
  %stepnumber=2,                    % the step between two line-numbers. If it's 1, each line will be numbered
  stringstyle=\color{mymauve},     % string literal style
  tabsize=2,                       % sets default tabsize to 2 spaces
  title=\lstname                   % show the filename of files included with \lstinputlisting; also try caption instead of title
}


\begin{center} 
               \section*{\texttt{Solutions to Homework 1}}
\end{center} 


               \subsection*{Exercise 1}

Adding page 5 as asked (pages 3 and 5 link to each other) gives the new link matrix:
\begin{align*}
A = \begin{bmatrix}
             0            &        0              & \frac{1}{2} & \frac{1}{2} &      0       \\[0.3em]
       \frac{1}{3} &       0              &           0         &         0          &       0       \\[0.3em]
       \frac{1}{3} &  \frac{1}{2}  &          0          & \frac{1}{2} &      1      \\[0.3em]
       \frac{1}{3} & \frac{1}{2}   &          0          &        0           &      0      \\[0.3em]
              0           &             0         & \frac{1}{2}  &        0          &      0        \\[0.3em]
     \end{bmatrix}
\end{align*}
As before,  we are looking for an eigenvector $\mathbf{x} = [ x_1, x_2, x_3, x_4, x_5]^T$ corresponding to the eigenvalue 1 (which exists because $\mathbf{A}$ is column-stochastic). This $\mathbf{x}$
will be our ranking. Solve  $\mathbf{A} \mathbf{x} = \mathbf{x}$, i.e. $(\mathbf{A} -  \mathbf{I}) \mathbf{x} = 0$, for $\mathbf{x}$ :
\begin{alignat}{5}
            -x_1        &                                 & +\frac{1}{2}x_3  &   +\frac{1}{2}x_4  &          & =0 \\
 \frac{1}{3}x_1 &            -x_2            &                               &                                &          &=0 \\
 \frac{1}{3}x_1 &  +\frac{1}{2}x_2   &           -x_3            &  +\frac{1}{2}x_4   & +x_5 &=0\\
 \frac{1}{3}x_1 & +\frac{1}{2}x_2   &                               &           - x_4              &         &=0\\
                            &                               &\frac{1}{2}x_3    &                                  & -x_5 &=0
\end{alignat}

Solve `by hand' first, then confirm solution with \texttt{MATLAB}. 
Set $x_3 = 2$ and $x_5 = 1$ to satisfy equation (5). Then subtract (4) from (3) to obtain $x_4 = 2/3$, plug $x_3$ and $x_4$ 
into equation (1) to get $x_1 = 4/3$ . Finally plug $x_1$ into equation (2) to get $x_2 = 4/9$. 


\bigskip
So we've got one eigenvector: $\mathbf{x} = [ 4/3, 4/9, 2, 2/3, 1]^T$ corresponding to $\lambda = 1$; there are many more solutions - as many as you'd like, all collinear to $\mathbf{x}$. (We can agree to pick the one
that ensures the components of $\mathbf{x}$ sum to $1$, i.e. scale $\mathbf{x}$ by dividing each component by the sum of $\mathbf{x}$'s components.)



\pagebreak
Here's some \texttt{MATLAB} that does the same:

{\ttfamily
\begin{lstlisting}
A = [ 0         0      1/2    1/2       0  ;     
     1/3        0       0      0        0  ;   
     1/3       1/2      0     1/2       1  ;     
     1/3       1/2      0      0        0  ;    
      0         0      1/2     0        0 ];

[V D] = eig(A1);
disp('the eigenvector associated with eigenvalue 1:')
V(:,1)
x = V(:,1)/sum(V(:,1))
figure(1)
bar(x)
\end{lstlisting}
}

\begin{center}
\includegraphics[scale=0.8]{Exercise1rank}
\end{center}


Thus the new ranking is
$$
 x = [\ 0.2449, \     0.0816, \     0.3673,\     0.1224, \     0.1837 \ ]
 $$
 
 and page 3 is now ranked the highest.
 \pagebreak
 

               \subsection*{Exercise 7}

Let $\mathbf{A}$ and $\mathbf{S}$ be column stochastic matrices, i.e. $\sum_i A_{ij} = 1$ and $\sum_i S_{ij} = 1$ for every $j$-th column of $\mathbf{A}$ or $\mathbf{S}$. Let $0 \leq m \leq 1$
and let $\mathbf{M} = m\mathbf{A} + (1-m)\mathbf{S}$. Consider the sum of the elements in $\mathbf{M}$'s $j$-th column: 
\begin{align*}
\sum_i M_{ij} &= \sum_i (m A_{ij} +  (1 - m) S_{ij}) \\
&= \sum_i m A_{ij} +  \sum_i (1 - m) S_{ij} \\
&= m \sum_i A_{ij} + (1 - m) \sum_i S_{ij} \\
&= m + (1 - m)  \\
&= 1 
\end{align*}

This being true for any $j$, $\mathbf{M}$ is column-stochastic.

\bigskip

               \subsection*{Exercise 11}


 Here the link matrix $\mathbf{A}$ is the same as in problem 1.  Set $ m = 0.15$ and write down the matrix $\mathbf{M} = 0.85 \mathbf{A} + 0.15 \mathbf{S}$ where $\mathbf{S}$ is the $5 \times 5$ matrix each element of which is
 1/5.\\
 
 {\ttfamily
 \begin{lstlisting}
A = [ 0         0      1/2    1/2       0  ;     
     1/3        0       0      0        0  ;   
     1/3       1/2      0     1/2       1  ;     
     1/3       1/2      0      0        0  ;    
      0         0      1/2     0        0 ];

S = 1/5 * ones(5);
m = 0.15;
M = (1 - m)*A + m*S 
[V D] = eig(M)
% diag(D)
ranks = V(:,1) / sum(V(:,1))     
bar(ranks)
\end{lstlisting}
}

Here the output is:
$$
ranks = [\ 0.2371, \     0.0972, \    0.3489, \    0.1385, \    0.1783 \ ]
$$

Slightly different scores but the relative ranking of the pages is the same.
 
 
\begin{center}
\includegraphics[scale=0.7]{Exercise11rank}
\end{center}
\end{document}
\end{document}
This is never printed