
# Homework 9

Please answer the following questions in complete sentences in a typed, clearly prepared manuscript and submit the solution by the due date on Blackboard (Monday, November 13th, 2017, around 4-5 am)

## Problem 0: Homework checklist

• Please identify anyone, whether or not they are in the class, with whom you discussed your homework. This problem is worth 1 point, but on a multiplicative scale.

• Make sure you have included your source-code and prepared your solution according to the most recent Piazza note on homework submissions.

## Problem 1: Compare CG as described in class to the standard CG iteration

1. Implement a CG method based on the Lanczos method. That is, implement the Lanczos method to compute the matrix $\mT_k$ and $\mV_k$. Then solve $\mT_k \vy\itn{k} = \ve_1$ and compute $\vx = \normof{\vb} \mV_k \vy\itn{k}$. (All this notation is taken from the CG handout from class, here https://www.cs.purdue.edu/homes/dgleich/cs515-2017/notes/conjugate-gradient.pdf). Show the code for your implementation. At each step, you should compute the normalized residuals.

2. Compare the first 25 residuals from your Lanczos-based CG code with the a standard implementation of CG from: http://www.cs.purdue.edu/homes/dgleich/cs515-2017/julia/cg.jl for the linear system

  n = 100
on = ones(Int64,n)
A = spdiagm((-2*on[1:end-1],4*on,-2*on[1:end-1]),(-1,0,1))
b = ones(n)

3. Using the cg.jl function, look at how many iterations are required for CG to converge to a tolerance of $10^{-8}$ for the matrix in the last part. Determine how this scales with $n$.

## Problem 2: Orthogonality of Lanczos

Let $\lambda_1 = 0.1$ and $\lambda_n = 100$, $\rho = 0.9$, $n=30$.
Consider the $n$-by-$n$ matrix with diagonal elements
(This is called the Strako\v{s} matrix.)

1. Implement the Lanczos method starting from a a random vector $\vv_1$ and the vector $\vv_1 = \ve/\sqrt{n}$ and then plot the quantity $\log(\normof{\mV_k^T \mV_k - \mI}+10^{-20})$ for $k=1$ to $30$. Describe what you SHOULD find and what you actually find. Do your results depend on the starting vector?

2. Plot $\log(|\vv_1^T \vv_k| + 10^{-20})$ for the $k=1$ to $30$. Also plot $\log(|\vv_{k-2}^T \vv_k| + 10^{-20})$ for $k=3$ to $30$.

3. What is $\beta_{31}?$ What should it be?

4. Plot $\log(\normof{\mA \mV_k - \mV_{k+1} \mT_{k+1}} + 10^{-20})$ for $k=1$ to $60$.