%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
% This top part of the document is called the 'preamble'.  Modify it with caution!
%
% The real document starts below where it says 'The main document starts here'.

\documentclass[12pt]{article}

\usepackage{amssymb,amsmath,amsthm}
\usepackage[top=1in, bottom=1in, left=1.25in, right=1.25in]{geometry}
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage{enumerate}
\usepackage{verbatim}

% Comment the following line to use TeX's default font of Computer Modern.
\usepackage{times,txfonts}

\newtheoremstyle{homework}% name of the style to be used
  {18pt}% measure of space to leave above the theorem. E.g.: 3pt
  {12pt}% measure of space to leave below the theorem. E.g.: 3pt
  {}% name of font to use in the body of the theorem
  {}% measure of space to indent
  {\bfseries}% name of head font
  {:}% punctuation between head and body
  {2ex}% space after theorem head; " " = normal interword space
  {}% Manually specify head
\theoremstyle{homework} 

% Set up an Exercise environment and a Solution label.
\newtheorem*{exercisecore}{\@currentlabel}
\newenvironment{exercise}[1]
{\def\@currentlabel{#1}\exercisecore}
{\endexercisecore}

\newcommand{\localhead}[1]{\par\smallskip\noindent\textbf{#1}\nobreak\\}%
\newcommand\solution{\localhead{Solution:}}



% \newcommand{includematlab}[1]{\verbatiminput{#1}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Stuff for getting the name/document date/title across the header
\makeatletter
\RequirePackage{fancyhdr}
\pagestyle{fancy}
\fancyfoot[C]{\ifnum \value{page} > 1\relax\thepage\fi}
\fancyhead[L]{\ifx\@doclabel\@empty\else\@doclabel\fi}
\fancyhead[C]{\ifx\@docdate\@empty\else\@docdate\fi}
\fancyhead[R]{\ifx\@docauthor\@empty\else\@docauthor\fi}
\headheight 15pt

\def\doclabel#1{\gdef\@doclabel{#1}}
\doclabel{Use {\tt\textbackslash doclabel\{MY LABEL\}}.}
\def\docdate#1{\gdef\@docdate{#1}}
\docdate{Use {\tt\textbackslash docdate\{MY DATE\}}.}
\def\docauthor#1{\gdef\@docauthor{#1}}
\docauthor{Use {\tt\textbackslash docauthor\{MY NAME\}}.}
\makeatother

%% General formatting parameters
\parindent 0pt
\parskip 12pt plus 1pt

% Shortcuts for blackboard bold number sets (reals, integers, etc.)
\newcommand{\Reals}{\ensuremath{\mathbb R}}
\newcommand{\Nats}{\ensuremath{\mathbb N}}
\newcommand{\Ints}{\ensuremath{\mathbb Z}}
\newcommand{\Rats}{\ensuremath{\mathbb Q}}
\newcommand{\Cplx}{\ensuremath{\mathbb C}}
%% Some equivalents that some people may prefer.
\let\RR\Reals
\let\NN\Nats
\let\II\Ints
\let\CC\Cplx

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
% The main document start here.

% The following commands set up the material that appears in the header.
\doclabel{Math 426: Homework 4}
\docauthor{Your name here!}
\docdate{September 23, 2020}

\newcommand{\vv}{\mathbf{v}}
\begin{document}


\begin{exercise}{Chapter 4: 2 (c)}
For full credit you must write your own version of the secant method.
Your function should have the signature

\begin{verbatim} 
function [r,hist] = secant(f,x0,x1,ftol,xtol,Nmax)

end
\end{verbatim}

The input values are
\begin{itemize}
\item \texttt{f}, the function to find a root of.
\item \texttt{x0}, \texttt{x1} the first two iteration values.
\item \texttt{ftol}, the tolerance for stopping based of the value of \texttt{f}
\item \texttt{xtol}, the tolerance for stopping based on changes in \texttt{x}
\item \texttt{Nmax}, the maximum number of iterations
\end{itemize}

Your function should exit with an error if more than \texttt{Nmax} iterations
are used.  It should return whenever $|f(x)|<f_{\text{tol}}$ or $|x_n-x_{n-1}|<x_{\text{tol}}$.

The return values should be \texttt{r}, the estimate of the root's position,
and \texttt{hist}, a list of all estimates starting with \texttt{x0} and \texttt{x1} and ending with the final estimate \texttt{r}.

Test that your function works by finding three different ways to call it
so that iteration stops for each of the three possible reasoins.

To answer the problem in the textbook, you will want to call your functin with 
$x_{\rm tol}=0$ to ensure that only the $f_{\rm tol}$ condition is used
to stop the iteration.
\end{exercise}

\begin{exercise}{Chapter 4: 3}
\end{exercise}

\begin{exercise}{Chapter 4: 8}
\end{exercise}

\begin{exercise}{Chapter 4: 12}  For full credit you must
use Theorem 4.5.1.
\end{exercise}

\begin{exercise}{Supplemental 1}
Suppose $f(x)$ is a differentiable function 
on $\mathbb{R}$ and $|f'(x)|\le 1/2$ for
all real numbers.  Show that
\[
|f(x)-f(y)|\le \frac{1}{2} |x-y|
\]
for all $x,y\in \mathbb{R}$.

Hint: Use Taylor's theorem, the zeroth order version, AKA the Mean Value Theorem.  Apply it centered at some point $x$ and then see what the theorem says about $f(y)$.

For context, look at equation (4.22) of the text, which defines a \textbf{contraction}.  You are showing that if $|f'(x)|\le 1/2$ for all $x$ then
$f$ is a contraction.  This is interesting because Theorem 4.5.2 says
that every contraction has a unique fixed point, and if you perform fixed
point iteration on the contraction then the iterates will converge to the fixed point.  You can think of Theorem 4.5.2 as a generalization of Theorem 4.5.1 (you can prove Theorem 4.5.1 directly from the more difficult Theorem 4.5.2).
\end{exercise}

\begin{exercise}{Chapter 4: 13}  
You will want to use Theorem 4.5.2!
\end{exercise}

\begin{exercise}{Chapter 4: 14}  
\end{exercise}

\end{document}