Numerical methods, approximation in the sense of the least squares to find Polynomial

approximationleast squaresnumerical methods

Given these table of points x = [-1 -1/2 0 1/2 1] and f(x) = [2 1 0 1 2]. Find the approximation polynomial in the sense of the least square with weight function $w(x) = 1.$

My attempt:

So we take the canonical base $1, x, x^2$ and thus we have the polynomial:

$$P(x) = c_0 + c_1x+c_2x^2$$

Our goal is to find $c_0, c_1, c_2$.

We write the system:
$$\left\{\begin{array}{l}c_0<1, 1>+c_1 <1, x> + c_2 <1, x^2>= <1, f>\\c_0<x,1>+c_1<x,x>+c_2<x,x^2>=<x,f>\\c_0<x^2,1>+c_1<x^2,x> +c_2<x^2,x^2>=<x^2,f>\end{array}\right.$$

Now we just calculate all the scalar products and find $c_0,c_1,c_2.$ My question is: how do I calculate the scalar product between 2 functions with discontinuous points? Do I just sum up the values of $x$ or $f$?And why is that? What is the intuition behind that?

Best Answer

Using the scalar product $$\langle f,g\rangle=\sum_{k=1}^5 w(x_k)f(x_k)g(x_k)$$ on the sample space gives the linear system $$ \pmatrix{5&0&2.5\\0&2.5&0\\2.5&0&2.125} \pmatrix{c_0\\c_1\\c_2} = \pmatrix{6\\0\\4.5} $$ leading to $c_1=0$. Eliminating $c_0$ gives $1.75c_2=3\implies c_2=\frac{12}7=1.7142857..$ and lastly $5c_0=6-\frac{30}7=\frac{12}7\implies c_0=\frac{12}{35}=0.342857..$.

Related Question