\documentclass[twoside]{article}

\usepackage{palatino}
\usepackage{camnum}

\textheight=22.5cm
\textwidth=15cm
\topmargin=-1cm
\oddsidemargin=0.5cm
\evensidemargin=0.5cm
\parindent=0pt
\parskip=6pt

\begin{document}
\begin{center}
  {\large \textbf{Mathematical Tripos Part IB: Easter 2001}}

  {\Large \textbf{Numerical Analysis -- Detailed Example
      11\footnote{Corrections and suggestions to these notes should
        be emailed to \texttt{a.shadrin@damtp.cam.ac.uk}. All handouts
        are available on the WWW at the URL 
        \texttt{http://www.damtp.cam.ac.uk/user/na/PartIB/Handouts.html}.}}}

  \vspace{8pt}
  \textbf{\textit{\LARGE Least squares polynomial fitting}}
\end{center}

Let
\begin{displaymath}
  \langle f,g\rangle =\int_{-1}^1 f(x)g(x) \CC{d}x
\end{displaymath}
and recall that
\begin{Eqnarray*}
  p_0(x)&\equiv&1,\\
  p_1(x)&=&x,\\
  p_2(x)&=&x^2-\Frac13,\\
  p_3(x)&=&x^3-\Frac35 x,\\
  p_4(x)&=&x^4-\Frac67 x^2+\Frac{3}{35}.
\end{Eqnarray*}
We wish to approximate $f(x)=\CC{e}^x$. Letting
\begin{displaymath}
  c_k=\frac{\langle p_k,f\rangle}{\langle p_k,k_k\rangle}
  =\frac{\int_{-1}^1 p_k(x)\CC{e}^{-x}\CC{d}x} {\int_{-1}^1 [p_k(x)]^2
  \CC{d}x}
\end{displaymath}
we have
\begin{Eqnarray*}
  c_0&=&\Frac12(\CC{e}-\CC{e}^{-1})\approx 1.175201,\\
  c_1&=&3\CC{e}^{-1}\approx 1.103638,\\
  c_2&=&\Frac{15}{4}\CC{e}-\Frac{105}{4}\CC{e}^{-1}\approx 0.536722,\\
  c_3&=&-\Frac{175}{4}\CC{e}+\Frac{1295}{4}\CC{e}^{-1} \approx
  0.176139,\\
  c_4&=&\Frac{50085}{4384}\CC{e}-\Frac{368235}{4384}\CC{e}^{-1}
  \approx 0.154895.
\end{Eqnarray*}
Therefore the least-squares approximation by a quartic is (up to four
significant digits)
\begin{displaymath}
  p(x)=\sum_{k=0}^4 c_k p_k(x)= 0.1549 x^4+ 0.1761 x^3 + 0.4040 x^2 +
  0.9980 x+  1.0096. 
\end{displaymath}

Plot the pointwise error $|\CC{e}^x-p(x)|$ to persude yourself that it
is smaller than $\approx 0.026$ for $x\in[-1,1]$.

\end{document}
%%% Local Variables: 
%%% mode: latex
%%% TeX-master: t
%%% End: 
