\documentclass[]{article}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc}
\else % if luatex or xelatex
  \ifxetex
    \usepackage{mathspec}
  \else
    \usepackage{fontspec}
  \fi
  \defaultfontfeatures{Ligatures=TeX,Scale=MatchLowercase}
\fi
% use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
% use microtype if available
\IfFileExists{microtype.sty}{%
\usepackage{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\usepackage{hyperref}
\hypersetup{unicode=true,
            pdftitle={Homework 5},
            pdfborder={0 0 0},
            breaklinks=true}
\urlstyle{same}  % don't use monospace font for urls
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
}
\setlength{\emergencystretch}{3em}  % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{0}
% Redefines (sub)paragraphs to behave more like sections
\ifx\paragraph\undefined\else
\let\oldparagraph\paragraph
\renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
\let\oldsubparagraph\subparagraph
\renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}}
\fi

\title{Homework 5}

\input{preamble.tex}
\title{Homework}



\begin{document}
\maketitle

Please answer the following questions in complete sentences in submit
the solution on Blackboard November 7, 2016 by 5pm.

\section{Homework 5}\label{homework-5}

\subsection{Problem 1 (20 points)}\label{problem-1-20-points}

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\item
  Chapter 8, Problem 1, Parts (a), (b) (5 points each)
\item
  (5 points) Use the setup from chapter 8, Problem 1. Suppose we present
  the data from part (b) as the number of milliseconds from 1900. (This
  involves multiplying each ``year'' by \texttt{365*24*60*60*1000}.)
  Evaluate the quadratic Lagrange interpolant directly, and via the
  Barycentric formulation at 50 uniformly spaced points between (and
  including) the interpolation end points (e.g.~1900 and 1940 translated
  into milliseconds). Report on any differences. (Hint: there should be
  something weird \ldots{})
\item
  (5 points) \textbf{Note, there are much better ways of evaluating the
  barycentric Lagrange polynomial.} Here is one that is based on a
  Matlab code by one of the authors who recognized the importance of
  Barycentric interpolation.

\begin{verbatim}
function barylag(x,y,xx)
    # direct port of 
    # http://www.mathworks.com/matlabcentral/fileexchange/...
    #    4478-barycentric-lagrange-interpolating-polynomials-...
    #    and-lebesgue-constant/content/barylag.m
    # to Julia. Not that better implmentations in Julia are possible.
    M = length(x)
    N = length(xx)
    @assert M == length(y)
    X = repmat(x,1,M)
    W = repmat(1./prod(X-X'+eye(M),1),N,1)
    xdist=repmat(xx,1,M)-repmat(x',N,1)
    fixi,fixj = findnz(xdist.==0)
    H=W./xdist
    p=vec((H*y)./sum(H,2))
    p[fixi] = y[fixj]
    return p
end
\end{verbatim}

  Use this code to interpolate the data in part (b) instead, using the
  values of the data in milliseconds. Report on how this code addressed
  the problem. (That is, you must explain why this code was able to fix
  the issue you found in part 2.)
\end{enumerate}

\subsection{Problem 2 (20 points)}\label{problem-2-20-points}

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\item
  Chapter 8, Problem 5.
\item
  Implement a Julia function that computes the following:

\begin{verbatim}
"""
`chebspace`
===========

A Chebyshev analog of linspace for polynomial interpolation

* `chebspace(a,b)` generates an array of 100 Chebyshev points 
between `a` and `b`
* `chebspace(a,b,n)` generates an array of `n` points between a, b
and for `n=1`, this returns b.
function chebspace(a,b,n)
# fill this in!
end
function chebspace(a,b)
    return chebspace(a,b,100)
end
\end{verbatim}

  (Hint, see equation 8.15)
\end{enumerate}

\subsection{Problem 3 (10 points)}\label{problem-3-10-points}

Write a paragraph or two (100-200 words) about what you learned about
polynomials and polynomial interpolation. You should also think about
answering the following questions:

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\itemsep1pt\parskip0pt\parsep0pt
\item
  Do you think you'd ever use polynomial interpolation?
\item
  If so, how?
\item
  If not, why not?
\end{enumerate}

Be honest, but remember to be thoughtful.

\subsection{Problem 4 (10 points)}\label{problem-4-10-points}

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\item
  Download and install ApproxFun. Then type \texttt{using ApproxFun} to
  get it added to your Julia instance. Also type \texttt{using Plots} to
  get the plotting interaface.
\item
  Run

\begin{verbatim}
f = Fun(x->sign(x))
plot(f)
\end{verbatim}

  How does this relate to the Weistrauss approximation theorem?
\item
  Try using ApproxFun to integrate the most complicated function (in one
  dimension) that you can think of! Can you stump ApproxFun?
\item
  One of the advantages of Chebfun is we can get computer
  representations of functions (as polynomials) that have no analytic
  form what-so-ever. Consider the following code which builds a
  polynomial approximation of
  \[ \rho(t) = \max |\lambda_i\left( t \bmat{1 & 2 & 0 \\ 0 & 2 & 1 \\ 1 & 0 & 2} + 
                      (1-t) \bmat{1 & 1 & 0 \\ 1 & -1 & 1 \\ -1 & 1 & 1} \right) | \]
  here $\lambda_i$ is just the $i$th eigenvalue. So this is looking at
  the largest magnitude eigenvalue. (Example from Chebfun:
  \url{http://www.chebfun.org/examples/approx/NoisyNonsmooth.html})

\begin{verbatim}
A = [1 2 0; 0 2 1; 1 0 2.0]
B = [1 1 0; 1 -1 1; -1 1 1.0]
f = Fun(t -> maximum(abs(eigvals(t*A + (1-t)*B))),[0,1])   
plot(f)
\end{verbatim}

  Run this code and show your result!
\item
  (Fun bonus question, worth no points.) This requires Matlab. Download
  and install the Matlab package \texttt{chebfun} Run
  \texttt{chebsnake('equi')} (Remember this when you are tempted to use
  equally spaced points for polynomial interpolation!)
\end{enumerate}

\subsection{Problem 5 (40 points)}\label{problem-5-40-points}

\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\itemsep1pt\parskip0pt\parsep0pt
\item
  (10 points) Chapter 9, Exercise 1,
\item
  (10 points) Chapter 9, Exercise 2.
\item
  (10 points) Chapter 9, Exercise 3.
\item
  (10 points) Chapter 9, Exercise 5.
\end{enumerate}

\end{document}
