\documentclass[12pt]{article}

\usepackage[margin=1in]{geometry}
\usepackage[small]{titlesec}
\usepackage{graphicx}
\usepackage{amsmath}
\newcommand{\Var}{\mathrm{Var}}
\newcommand{\sd}{\mathrm{sd}}
\usepackage{listings}

\newcommand{\ds}{\displaystyle}


\newpagestyle{main}[\small]{
	\headrule
	\sethead[\usepage][][]
	{}{}{\usepage}
}

\setlength{\parindent}{0pt}
\setlength{\parskip}{1.5ex}

\title{\vspace{-2cm} \sc Math 20 -- Problem Set 7 (due August 22) \vspace{-2.1cm}}
% \author{due \textbf{Friday, August 4}}

\date{}

 
\begin{document}
\maketitle
% \pagestyle{main}
% \pagenumbering{gobble}

%{\textbf{Name} \underline{\hspace{10cm}} } \\

This problem set is due at the \emph{beginning} of class.  This is just the problem list; please work out these problems on a different sheet of paper.  Please write neatly, staple the pages together, and explain your work where appropriate.  \textbf{When needed, use R or some other software to do your calculations.  Submit your answers (and justifications) but not your code.} You may find the following matrix commands useful. \\

\textbf{Matrix Commands in R}:

To create a matrix, create a single list of all entries, filling in the first column, then the second, etc.  Then specify the number of rows and columns using the \texttt{nrow} and \texttt{ncol} commands.  Put this all together using the \texttt{matrix} function, as in the examples below.
\begin{lstlisting}
> A <- matrix(c(2, 4, 6, 8, 10, 12, 14, 16), nrow = 4, ncol=2)
> A
     [,1] [,2]
[1,]    2   10
[2,]    4   12
[3,]    6   14
[4,]    8   16

> B <- matrix(c(6, 5, 4, 3, 2, 1), nrow = 2, ncol = 3)
> B
     [,1] [,2] [,3]
[1,]    6    4    2
[2,]    5    3    1
\end{lstlisting}


We can add matrices componentwise the same way we would for numbers.

\begin{lstlisting}
> C <- A+A
> C
     [,1] [,2]
[1,]    4   20
[2,]    8   24
[3,]   12   28
[4,]   16   32
> C+A
     [,1] [,2]
[1,]    6   30
[2,]   12   36
[3,]   18   42
[4,]   24   48
\end{lstlisting}

We cannot simply use \texttt{*} to multiply matrices, as it would try to perform this operation componentwise.  Instead, use \texttt{\%*\%}:

\begin{lstlisting}
> D <- A %*% B
> D
     [,1] [,2] [,3]
[1,]   62   38   14
[2,]   84   52   20
[3,]  106   66   26
[4,]  128   80   32
\end{lstlisting}

To create the diagonal $n$-by-$n$ matrix, use $\texttt{diag(n)}$.

\begin{lstlisting}
> I <- diag(3)
> I
     [,1] [,2] [,3]
[1,]    1    0    0
[2,]    0    1    0
[3,]    0    0    1
\end{lstlisting}

Finally, invert a square (invertible) matrix $P$ using the function $\texttt{solve(P)}$:

\begin{lstlisting}
> P <- matrix(c(0.9, 0.2, 0.1, 0.2), nrow=2, ncol=2)
> P
     [,1] [,2]
[1,]  0.9  0.1
[2,]  0.2  0.2
> solve(P)
      [,1]   [,2]
[1,]  1.25 -0.625
[2,] -1.25  5.625
> solve(diag(2) - P)
          [,1]     [,2]
[1,] 13.333333 1.666667
[2,]  3.333333 1.666667
\end{lstlisting}

\newpage

\textbf{Problem List}

\begin{enumerate}

\item GS p. 413 \#2

\item GS p. 413 \#8

\item GS p. 422 \#12 (\textbf{Nc} is the (column) vector of row sums of \textbf{N})

\item GS p. 422 \#18

\item GS p. 442 \#2 (don't use a computer for c), and show your work)

\end{enumerate}


\end{document}
