%%  File:  curveFittingGuide.tex
%%
%%  Study Guide for Numerical Methods with MATLAB
%%  Chapter 9, "Least Squares Fitting of a Curve to Data"
%%
%%  Gerald Recktenwald,  gerry@me.pdx.edu
%%  December 2001


\documentclass{article}

\usepackage{studyGuide}
\renewcommand{\guideName}{Study Guide for Least Squares Curve Fitting}


\title{Study Guide for\\
       Least Squares Fitting of a Curve to Data}
\author{Gerald Recktenwald}

\newcounter{enumSave}

\begin{document}

%\maketitle

% -------------------------
\section*{Bare Essentials}
At the end of this chapter you should be able to
\begin{enumerate}
    \item   Identify the criteria for obtaining a least squares fit.  (What is minimized?)
    \item   Manually evaluate the formulas for the slope and intercept of a
            line fit to data.
    \item   Derive the transformations for fitting data to $y=c_1e^{c_2x}$ and $y=c_1x^{c_2}$.
    \item   Manually compute the $R^2$ statistic for a line fit.
\setcounter{enumSave}{\value{enumi}}
\end{enumerate}


\bigskip
\noindent To perform basic solutions of linear systems with \MATLAB\ you will need to
\begin{enumerate}
\setcounter{enumi}{\value{enumSave}}
    \item   Use the \texttt{linefit} function in the NMM Toolbox to obtain a least
            squares line fit to data.
    \item   Use the \texttt{linefit} function in the NMM Toolbox to obtain least
            squares line fits to linearized transformations of $y=c_1e^{c_2x}$ and $y=c_1x^{c_2}$.
    \item   Use the built-in \texttt{polyfit} function to obtain a least squares
            fit to a polynomial in $x$.  Use the built-in \texttt{polyval} function to evaluate
            the polynomial obtained from \texttt{polyfit} at any $x$.
    \item   Plot a comparison of a least squares fit and the data used to obtain the fit.
\end{enumerate}


% -------------------------
\section*{An Expanded Core of Knowledge}
After mastering the bare essentials you should move on to a deeper understanding
of the fundamentals.  Doing so involves being able to
\begin{enumerate}
    \item   Form the overdetermined system of equations equations for an linear combination of
            arbitrary basis functions.
\setcounter{enumSave}{\value{enumi}}
\end{enumerate}

\bigskip
\noindent To perform more advanced solutions of linear systems with \MATLAB\ you will need to
\begin{enumerate}
\setcounter{enumi}{\value{enumSave}}
    \item   Use the \texttt{fitnorm} and \texttt{fitQR} functions from the NMM Toolbox to
            obtain least squares fits to linear combinations of arbitrary basis functions.
    \item   Assign the elements of the matrix \texttt{A} of the overdetermined system
            for a given choice of basis functions.  Given this matrix and a vector
            of $y$ data, obtain the coefficients of the fit by solving the normal equations.
    \item   Repeat the steps in the previous bullet, but obtain the least squares fit
            directly with the backslash operator.
    \item   Given the matrix of the overdetermined system for the fit, and a vector of $y$
            data values, use the \verb|\| operator to obtain the coefficients that minimizes
            \pnorm{r}{2} for the overdetermined system.
\end{enumerate}

% \clearpage

% -------------------------
\section*{Developing Mastery}
Working toward mastery of solving systems of equations you will need to
\begin{enumerate}
    \item   Identify the primary properties of the QR factorization that enable
            the least squares solution to be obtained with the $Q$ and $R$ matrices.
\end{enumerate}


\end{document}
