the best approximation to sgn$(x)$ in the least square sense

247 Views Asked by At

Find the best approximation to $f(x)$ = sgn$(x)$ by a function $f^*(x) = \alpha_0 + \alpha_1 x + \alpha_2x^3$ on the interval $[−1, 1]$, in the least squares sense.

I know what mean sgn$(x)$ but I don't know what mean $f^*(x)$ and how to count best approximation. Anyone helps?

2

There are 2 best solutions below

4
On

$f^*(x)$ is just a function which is defined in the problem. You could call it $g(x)$ if you prefer. It depends on the constants $\alpha_0, \alpha_1, \alpha_2$. You are supposed to determine the value of the $\alpha $s to minimize the error. The error in the least squares sense is $\int_{-1}^1 (f(x)-f^*(x))^2\; dx$, so evaluate that, set the derivatives with respect to the $\alpha$s to zero, etc.

1
On

This is a challenging problem which requires forethought.

To begin, since the target function is odd, only use odd functions. Let $k$ be an positive integer: $$ \int_{-a}^{a} \text{sgn }(x) x^{2k} dx = \int_{-a}^{0} -x^{2k} dx + \int_{0}^{a} x^{2k} dx = 0 $$ The function sgn$(x)$ is plotted below.

sgn

Even functions are excluded, cutting the computational load in half. A further reduction is possible. Because of odd symmetry, only compute half of the integrals: $$ \int_{-a}^{a} \text{sgn }(x) x^{2k-1} dx = \int_{-a}^{0} -x^{2k-1} dx + \int_{0}^{a} x^{2k-1} dx = 2 \int_{0}^{a} x^{2k-1} dx. $$

The first attempt at approximation is with a sequence of odd monomials through order $d$ $$ \text{sgn }(x) \approx a_{1}x + a_{3} x^{3} + \cdots + a_{d} x^{d} = \sum_{k=1}^{d} a_{2k-1} x^{2k-1} $$

The least squares solution is defined as $$ a_{LS} = \left\{ a \in \mathbb{R}^{m} \colon \int_{-1}^{1} \left( \text{sgn }(x) - \sum_{k=1}^{2m-1} a_{2k-1} x^{2k-1} \right)^{2} dx \text{ is minimized} \right\} $$

The linear system to solve corresponds to the normal equations $$ % \left[ \begin{array}{cccc} \int_{0}^{1} x \cdot x dx & \int_{0}^{1} x \cdot x^{3} dx & \dots & \int_{0}^{1} x \cdot x^{2m-1} dx\\ % \int_{0}^{1} x^{3} \cdot x dx & \int_{0}^{1} x^{3} \cdot x^{3} dx & \dots & \int_{0}^{1} x^{3} \cdot x^{2m-1} dx\\ % \vdots & \vdots & & \vdots \\ % \int_{0}^{1} x^{2m-1} \cdot x dx & \int_{0}^{1} x^{2m-1} \cdot x^{3} dx & \dots & \int_{0}^{1} x^{2m-1} \cdot x^{2m-1} dx\\ % \end{array} \right] % \left[ \begin{array}{c} a_{1} \\ a_{3} \\ \vdots \\ a_{2m-1} \end{array} \right] = \left[ \begin{array}{c} \int_{0}^{1} x dx \\ \int_{0}^{1} x^{3} dx \\ \vdots \\ \int_{0}^{1} x^{2m-1} dx \end{array} \right] $$

Below are plots showing a sequence of approximations where the number of terms is $d$:

all three fits

A problem arises because the amplitudes have unbounded growth. The plot sequence displays the logarithm of the absolute value of the amplitudes $a$. The points marked with red dots were negative. Using the monimials, the amplitudes have an invariance in form.

monomials

In remedy, switch from the monomial basis to a nearly orthogonal basis like the Legendre polynomials. Abandon orthogonality and use linear independence. Then we will have invariance in value.

Legendre