2201NSC
Least Square Fitting
In applications, one is often faced with over-determined linear systems. For example, we may have a bunch of data points that we have reasons to believe should fit on a straight line. But real-life data points rarely match predictions exactly.
The challenge here is to develop a method for obtaining the best fit or approximation of a specified kind to a given set of data points.
Experiments yield data (assume $x_i$ distinct and exact) $$ (x_1, y_1),\;(x_2,y_2),\;\cdots, \;(x_n, y_n) $$ which include measurement error. Theory may predict polynomial relation between $x$ and $y$. But experimental data points rarely match theoretical predictions exactly.
We seek a least squares polynomial function of best fit (e.g. least squares line of best fit or regression line).
We seek a least squares polynomial function of best fit (e.g. least squares line of best fit or regression line).
Example: Quadratic fit. Suppose some physical system is modeled by a quadratic function $p(x).$ Data in the form $(x,p(x))$ have been recorded as $$ (1,5),\ (2,2),\ (4,7),\ (5,10). $$ Find the least squares approximation for $p(x)$.
Example: Quadratic fit. $ (1,5),\ (2,2),\ (4,7),\ (5,10). $ Find the least squares approximation for $p(x).$
Consider the quadratic function $p(x) = a_2 x^2 + a_1 x + a_0$. To find the least squares approximation we need to solve the linear system:
\[ \left\{ \begin{array}{ccccccc} a_2 (1)^2 & + & a_1 (1)& + & a_0 & = & 5 \\ a_2 (2)^2 & + & a_1 (2)& + & a_0 & = & 2 \\ a_2 (4)^2 & + & a_1 (4)& + & a_0 & = & 7 \\ a_2 (5)^2 & + & a_1 (5)& + & a_0 & = & 10 \\ \end{array} \right. \]
\[ \left\{ \begin{array}{ccrcrcc} a_2 & + & a_1 & + & a_0 & = & 5 \\ 4a_2 & + & 2a_1 & + & a_0 & = & 2 \\ 16a_2 & + & 4a_1& + & a_0 & = & 7 \\ 25a_2 & + & 5a_1 & + & a_0 & = & 10 \\ \end{array} \right. \]
\[ \left( \begin{array}{ccc} 1 & 1 & 1 \\ 4 & 2 & 1 \\ 16 & 4 & 1 \\ 25 & 5 & 1 \\ \end{array} \right) \left( \begin{array}{c} a_2 \\ a_1 \\ a_0 \\ \end{array} \right) = \left( \begin{array}{c} 5 \\ 2 \\ 7 \\ 10 \\ \end{array} \right) \]
\[ \underbrace{\left( \begin{array}{ccc} \begin{array}{ccc} 1 & 1 & 1 \\ 4 & 2 & 1 \\ 16 & 4 & 1 \\ 25 & 5 & 1 \\ \end{array} \end{array} \right)}_{{\Large A}} \underbrace{\left( \begin{array}{c} a_2 \\ a_1 \\ a_0 \\ \end{array} \right)}_{{\Large \mathbf x}} = \underbrace{\left( \begin{array}{c} 5 \\ 2 \\ 7 \\ 10 \\ \end{array} \right)}_{{\Large \mathbf b}} \]
Example: Quadratic fit. $ (1,5),\ (2,2),\ (4,7),\ (5,10). $ Find the least squares approximation for $p(x).$
\[ \underbrace{\left( \begin{array}{ccc} 1 & 1 & 1 \\ 4 & 2 & 1 \\ 16 & 4 & 1 \\ 25 & 5 & 1 \\ \end{array} \right)}_{A} \underbrace{\left( \begin{array}{c} a_2 \\ a_1 \\ a_0 \\ \end{array} \right)}_{\mathbf x} = \underbrace{\left( \begin{array}{c} 5 \\ 2 \\ 7 \\ 10 \\ \end{array} \right)}_{\mathbf b} \]
So we have $A\mathbf x = \mathbf b$. This is an over-determined and inconsistent system but the columns of $A$ are linearly independent. Then $A^TA$ is invertible.
Example: Quadratic fit. $ (1,5),\ (2,2),\ (4,7),\ (5,10). $ Find the least squares approximation for $p(x).$
\[\Ra\;\; \underbrace{\left( \begin{array}{ccc} 1 & 4 & 15 & 25\\ 1 & 2 & 4 & 5\\ 1 & 1 & 1 & 1 \end{array} \right)}_{A^T} \underbrace{\left( \begin{array}{ccc} 1 & 1 & 1 \\ 4 & 2 & 1 \\ 16 & 4 & 1 \\ 25 & 5 & 1 \\ \end{array} \right)}_{A} \underbrace{\left( \begin{array}{c} a_2 \\ a_1 \\ a_0 \\ \end{array} \right)}_{\mathbf x} = \underbrace{\left( \begin{array}{ccc} 1 & 4 & 15 & 25\\ 1 & 2 & 4 & 5\\ 1 & 1 & 1 & 1 \end{array} \right)}_{A^T} \underbrace{\left( \begin{array}{c} 5 \\ 2 \\ 7 \\ 10 \\ \end{array} \right)}_{\mathbf b} \]
Since $\,A^TA\,$ is invertible, then the least squares approximation is
$\ds \hat{\mathbf x} = \left(A^T A\right)^{-1}A^T \mathbf b$ $= \left( \begin{array}{r} 1 \\ -\dfrac{9}{2} \\ 8 \\ \end{array} \right) $ $\;\,\Ra \;\, p(x) = x^2 - \dfrac{9}{2}x+8. $
Data: $(1,5),\ (2,2),\ (4,7),\ (5,10).$
The Fourier series of a real function $f$ defined on the interval $(-p,p)$ is given by
\( f(x)=\ds\frac{a_0}{2}+\sum_{n=1}^{\infty}\left(a_n\,\cos \left(\frac{n\, \pi}{p}x\right)+b_n\,\sin \left(\frac{n\, \pi}{p}x\right) \right), \)
where
\begin{eqnarray*} a_0&=&\frac{1}{p}\int_{-p}^pf(x)\,dx,\\ a_n&=&\frac{1}{p}\int_{-p}^pf(x)\,\cos \left(\frac{n\, \pi}{p}x\right)\,dx,\\ b_n&=&\frac{1}{p}\int_{-p}^pf(x)\,\sin \left(\frac{n\, \pi}{p}x\right)\,dx. \end{eqnarray*}
The Fourier series is named in honor of Jean Baptiste Joseph Fourier (1768-1830).
Example: Consider the function defined by $f(x)=x+\pi$ for $-\pi < x < \pi $ and $f(x)=f(x+2\pi)$ for $-\infty < x < \infty$. Its Fourier series expansion is \[ f(x)=\pi+2\sum_{n=1}^{\infty}\frac{\left(-1\right)^{n+1}}{n}\sin (n\,x). \]
Consider the square wave
The square wave Applets inspired by: Jez Swanson |
|
Source: Trigonometric interpolation