-1

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?

Vinci
  • 9

2 Answers2

1

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

dantopa
  • 10,342
0

$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.

Ross Millikan
  • 374,822
  • Okey, but should i divide the integral into two parts from [-1,0] and [0,-1] because sgn(x) is not continous? – Vinci Dec 13 '16 at 14:57
  • Yes, you can do that. – Ross Millikan Dec 13 '16 at 15:00
  • so, I'm supposed to calculate deriverative for function with three variables? or is it okey if I'll separate them to three different deriveratives – Vinci Dec 13 '16 at 15:06
  • You need the derivative with respect to each one of them to be zero because if it weren't you could reduce the error by changing the value. Take the derivative with respect to each and set the resulting expression to zero. This will give you three equations in three unknowns. The $\alpha_0$ one should be trivial because that term is even while $f(x)$ is odd. – Ross Millikan Dec 13 '16 at 15:19