Least Squares - Using a Lower Degree Monomial

Thomas J. Kennedy

Contents:

Note that this is not a good approximation. This example is intended to demonstrate the impact of a poorly selected basis function.

Suppose that we want to approximate $f(x) = x^4$ for the domain $0 \leq x \leq 4$ using a monomial of degree 2… using a continuous approximation.

1 Setting Up

Let us start with what we know:

Since $\hat{\varphi}$ is a monomial… the single basis function is

which leads to…

$$ \begin{align} \hat{\varphi} &= c_0 \pi_2 \\ &= c_0 x^2 \\ \end{align} $$

Since we have one basis function… $A\vec{c} = \vec{b}$ takes the form…

$$ \left[\begin{array}{ll} \int\limits_{x=0}^{4} \pi_{0} \pi_{0} dx \\ \end{array}\right] \left[\begin{array}{c} c_0 \\ \end{array}\right] = \left[\begin{array}{l} \int\limits_{x=0}^{4} \pi_0 f dx\\ \end{array}\right] $$

Note how $A$ is a 1-by-1 matrix. We have one constant to compute.

2 Plugging Everything In

We know that

Let us plug everything in and use basic Algebra

$$ \begin{eqnarray} c_0 \int\limits_{x=0}^{4} x^4 dx &=& \int\limits_{x=0}^{4} x^6 dx \\ c_0 \frac{4^5}{5} &=& \frac{4^7}{7} \\ c_0 &=& \frac{4^7}{7} \frac{5}{4^5} \\ c_0 &=& \frac{4^2}{7} \frac{5}{1} \\ c_0 &=& \frac{80}{7} \\ \end{eqnarray} $$

3 The Result

Now that we have $c_0$… we can write the approximation function as

$$ \hat{\varphi} = \frac{80}{7} x^2 $$

4 What is the Error

Now… for the important question: How “bad” is our approximation?

The error can be evaluated using

$$ \begin{eqnarray} E^2(x) &=& ||f(x) - \hat{\varphi}(x)|| \\ &=& \int\limits_{\mathbb{R}} \left(f - \hat{\varphi} \right)^2 d\lambda(x) \\ &=& \int\limits_{\mathbb{R}} f^2 d\lambda(x) -2\int\limits_{\mathbb{R}} \hat{\varphi}f d\lambda(x) +\int\limits_{\mathbb{R}} \hat{\varphi}^2 d\lambda(x) \\ &=& \int\limits_{\mathbb{R}} \hat{\varphi}^2 d\lambda(x) -2\int\limits_{\mathbb{R}} \hat{\varphi}f d\lambda(x) + \int\limits_{\mathbb{R}} f^2 d\lambda(x) \\ \end{eqnarray} $$

Since we have a continuous approximation… with the domain $0 \leq x \leq 4$…

$$ \begin{eqnarray} E^2(x) &=& \int\limits_{\mathbb{R}} \hat{\varphi}^2 d\lambda(x) &-2\int\limits_{\mathbb{R}} \hat{\varphi}f d\lambda(x) &+ \int\limits_{\mathbb{R}} f^2 d\lambda(x) \\ &=& \int\limits_{x=0}^{4} \hat{\varphi}^2 dx &-2\int\limits_{x=0}^{4} \hat{\varphi}f dx &+ \int\limits_{x=0}^{4} f^2 dx \\ \end{eqnarray} $$

4.1 Plugging Everything In

Now… we plug in $f$ and $\hat{\varphi}$ (after preparing ourselves for some Calculus, Algebra, and Arithmetic).

$$ \begin{eqnarray} E^2(x) &=& \int\limits_{x=0}^{4} \hat{\varphi}^2 dx &-2\int\limits_{x=0}^{4} \hat{\varphi}f dx &+ \int\limits_{x=0}^{4} f^2 dx \\ &=& \int\limits_{x=0}^{4} \left(\frac{80}{7}x^2\right)^2 dx &-2\int\limits_{x=0}^{4} \left(\frac{80}{7}x^2\right)x^4 dx &+ \int\limits_{x=0}^{4} \left(x^4\right)^2 dx \\ &=& \int\limits_{x=0}^{4} \left(\frac{80}{7}x^2\right)^2 dx &-2\int\limits_{x=0}^{4} \left(\frac{80}{7}x^2\right)x^4 dx &+ \int\limits_{x=0}^{4} x^8 dx \\ &=& \int\limits_{x=0}^{4} \left(\frac{80}{7}x^2\right)^2 dx &-2\int\limits_{x=0}^{4} \left(\frac{80}{7}x^2\right)x^4 dx &+ \frac{1}{9}4^9\\ &=& \int\limits_{x=0}^{4} \left(\frac{80}{7}x^2\right)^2 dx &-\frac{160}{7}\int\limits_{x=0}^{4} x^6 dx &+ \frac{1}{9}4^9\\ &=& \int\limits_{x=0}^{4} \left(\frac{80}{7}x^2\right)^2 dx &-\frac{160}{49} 4^7 &+ \frac{1}{9}4^9\\ &=& \int\limits_{x=0}^{4} \left(\frac{80}{7}\right)^2\left(x^2\right)^2 dx &-\frac{160}{49} 4^7 &+ \frac{1}{9}4^9\\ &=& \left(\frac{80}{7}\right)^2 \int\limits_{x=0}^{4} \left(x^2\right)^2 dx &-\frac{160}{49} 4^7 &+ \frac{1}{9}4^9\\ &=& \left(\frac{80}{7}\right)^2 \int\limits_{x=0}^{4} x^4 dx &-\frac{160}{49} 4^7 &+ \frac{1}{9}4^9\\ &=& \left(\frac{80}{7}\right)^2 \frac{1}{5}4^5 dx &-\frac{160}{49} 4^7 &+ \frac{1}{9}4^9\\ &=& \left(\frac{80}{7}\right)^2 \frac{1}{5}4^5 dx &-\frac{16 \times 10 }{49} 4^7 &+ \frac{1}{9}4^9\\ &=& \left(\frac{80}{7}\right)^2 \frac{1}{5}4^5 dx &-\frac{10}{49} 4^9 &+ \frac{1}{9}4^9\\ &=& \frac{6400}{49 \times 5} 4^5 &-\frac{10}{49} 4^9 &+ \frac{1}{9}4^9\\ &=& \frac{6400}{49 \times 5} 4^5 &-\frac{10}{49} 4^9 &+ \frac{1}{9}4^9\\ &=& \frac{1280}{49} 4^5 &-\frac{10}{49} 4^9 &+ \frac{1}{9}4^9\\ &=& \frac{256 \times 5}{49} 4^5 &-\frac{10}{49} 4^9 &+ \frac{1}{9}4^9\\ &=& \frac{5}{49} 4^9 &-\frac{10}{49} 4^9 &+ \frac{1}{9}4^9\\ &=& -\frac{5}{49} 4^9 & &+ \frac{1}{9}4^9\\ &=& -\frac{5}{49} 4^9 + \frac{1}{9}4^9\\ &=& \left(-\frac{45}{441} + \frac{49}{441}\right)4^9 \\ &=& \frac{4}{441} 4^9 \\ &=& \frac{1}{441} 4^{10} \\ \end{eqnarray} $$

5 How Bad is It?

Since $E^2(x) = \frac{1}{441} 4^{10}$ we know that…

$$ \begin{eqnarray} E(x) &=& \sqrt{\frac{1}{441} 4^{10}} \\ &=& \sqrt{\frac{1}{441}} \sqrt{4^{10}} \\ &=& \sqrt{\frac{1}{441}} \left(4^{10}\right)^\frac{1}{2} \\ &=& \frac{1}{\sqrt{441}} \left(4^{10}\right)^\frac{1}{2} \\ &=& \frac{1}{\sqrt{441}} 4^{5} \\ &=& \frac{1}{\sqrt{441}} \left(2^2\right)^{5} \\ &=& \frac{1}{\sqrt{441}} 2^{10} \\ &=& \frac{1024}{\sqrt{441}} \\ &=& \frac{1024}{21} \\ &\approx& 48.76 \end{eqnarray} $$

$E(x)$ can be though of as the area between $f(x)$ and $\hat{\varphi}(x)$.

Let us examine the area under $f(x) = x^4$…

$$ \begin{eqnarray} \int\limits_{x=0}^{4} x^4 dx &=& \frac{1}{5} x^5 \Bigg |_{x=0}^{4} \\ &=& \frac{1}{5} 4^5 \\ &=& \frac{1024}{5} \\ &\approx& 204.8 \end{eqnarray} $$

We are off by $\approx 50$ when the know value is $\approx 200$. We are essentially off by 25%.