<?xml version="1.0" encoding="UTF-8"?>

<record version="1" id="245">
 <title>example of linear least squares</title>
 <name>ExampleOfLinearLeastSquares</name>
 <created>2007-03-24 10:42:50</created>
 <modified>2007-03-24 10:42:50</modified>
 <type>Topic</type>
 <creator id="1" name="bloftin"/>
 <modifier id="1" name="bloftin"/>
 <author id="1" name="bloftin"/>
 <classification>
	<category scheme="msc" code="06.20.Dk"/>
 </classification>
 <preamble>% this is the default PlanetMath preamble.  as your knowledge
% of TeX increases, you will probably want to edit this, but
% it should be fine as is for beginners.

% almost certainly you want these
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsfonts}

% used for TeXing text within eps files
%\usepackage{psfrag}
% need this for including graphics (\includegraphics)
\usepackage{graphicx}
% for neatly defining theorems and propositions
%\usepackage{amsthm}
% making logically defined graphics
%\usepackage{xypic}

% there are many more packages, add them here as you need them

% define commands here</preamble>
 <content>The assumption of linear least squares is that there is a linear relationship between our measurements $z$ and the variables to be estimated $x$

\begin{equation}
z = Mx + b
\end{equation}

For this example let us assume that our measurements are given in Table 1 and you can see them plotted in Figure 1.

\begin{center}
\begin{tabular}{ccccccccccc}
\hline \\ 
x &amp; -3.0 &amp; -2.5 &amp; -2.0 &amp; -1.5 &amp; -1.0 &amp; -0.5 &amp; 0.0 &amp; 0.5 &amp; 1.0 &amp; 1.5 \\
z &amp; -1.0 &amp; -0.25 &amp; 0.0 &amp; 0.25 &amp; 0.4 &amp; 0.7 &amp; 1.0 &amp; 1.1 &amp; 1.4 &amp; 1.8 \\ [2ex]
\hline 
\end{tabular}
\end{center}
\begin{center}
{\bf Table 1:} Example Data
\end{center}

The linear least squares solution to fit the given data is given by the equation

\begin{equation}
x_{fit} = (A^TA)^{-1}A^Tz
\end{equation}

The only not so obvious step before using a tool like Matlab, is to form the $A$ matrix, which is a combination of an identity vector and $x$ as a column vectors, such that

$$ A = [ \,\, 1 \,\, | \,\,x \,\,] $$

This is clarified by looking at the example code in Matlab, {LinearLeastSquares.m}{LinearLeastSquares.m}.  A plot of fitting the measurement data with a line such that it minimizes the the mean square of the error is shown in Figure 1.

The equation of the line to fit this data is then

$$z = 0.543 x + 0.947$$

\begin{center}
\includegraphics[scale=.6]{LinearLeastSquares.eps}

{\bf Figure 1:} Linear Fit of Example Data
\end{center}</content>
</record>
