[Math] Parabolic sine approximation

approximationlinear algebra

Problem Find a parabola ($f(x)=ax^2+bx+c$) that approximate the function sine the best on interval [0,$\pi$].

The distance between two solutions is calculated this way (in relation to scalar product): $\langle u,v \rangle=\int_0^\pi fg$.

My (wrong) solution I thought that I would get the solution by calculating the orthogonal projection $w=a+bx+cx^2$ of $v=\sin x$ on subspace $W=\langle u_1,u_2,u_3 \rangle=\langle 1,x,x^2\rangle$ using Gramm matrix. Then I have
$$\begin{pmatrix}\langle u_1, u_1\rangle&\langle u_1, u_2\rangle&\langle u_1, u_3\rangle\\
\langle u_2, u_1\rangle&\langle u_2, u_2\rangle&\langle u_2, u_3\rangle\\
\langle u_3, u_1\rangle&\langle u_3, u_2\rangle& \langle u_3, u_3\rangle\end{pmatrix}
\begin{pmatrix} a\\b\\c\end{pmatrix}=
\begin{pmatrix} \langle u_1, v\rangle\\
\langle u_2,v\rangle\\
\langle u_3, v\rangle \end{pmatrix}$$
So then
$$\begin{pmatrix} \int_0^\pi 1&\int_0^\pi x&\int_0^\pi x^2\\
\int_0^\pi x& \int_0^\pi x^2& \int_0^\pi x^3 \\
\int_0^\pi x^2&\int_0^\pi x^3&\int_0^\pi x^4\end{pmatrix}\begin{pmatrix} a\\b\\c\end{pmatrix}=\begin{pmatrix} \int_0^\pi \sin x\\\int_0^\pi x\sin x\\\int_0^\pi x^2 \sin x \end{pmatrix}$$
But solving these equations didn't give me any good answer. So my question is – is my way of solving it completely wrong (if so, can you give me hints how to do it otherwise)?

Thank you

Edit
Then$$
\begin{pmatrix} \pi&\frac{\pi^2}{2}&\frac{\pi^3}{3}\\
\frac{\pi^2}{2}&\frac{\pi^3}{3}&\frac{\pi^4}{4}\\
\frac{\pi^3}{3}&\frac{\pi^4}{4}&\frac{\pi^5}{5}\end{pmatrix}\begin{pmatrix} a\\b\\c\end{pmatrix}=\begin{pmatrix} 2\\\pi\\\pi^2-4 \end{pmatrix}$$
$$
\begin{pmatrix} \pi&\frac{\pi^2}{2}&\frac{\pi^3}{3}\\
0&\frac{\pi^3}{12}&\frac{\pi^4}{12}\\
0&\frac{\pi^4}{12}&\frac{4\pi^5}{45}\end{pmatrix}\begin{pmatrix} a\\b\\c\end{pmatrix}=\begin{pmatrix} 2\\0\\\frac{1}{3}\pi^2-4 \end{pmatrix}$$
$$
\begin{pmatrix} \pi&\frac{\pi^2}{2}&\frac{\pi^3}{3}\\
0&\frac{\pi^3}{12}&\frac{\pi^4}{12}\\
0&0&\frac{\pi^5}{180}\end{pmatrix}\begin{pmatrix} a\\b\\c\end{pmatrix}=\begin{pmatrix} 2\\0\\\frac{1}{3}\pi^2-4 \end{pmatrix}$$
Edit II My way (I have found the mistake I did) will get the result
$$f(x)=\dfrac{60(\pi^2-12)}{\pi^5}x^2-\dfrac{60(\pi^2-12)}{\pi^4}x+\dfrac{12(\pi^2-10)}{\pi^3}$$
which I hope is the right answer with error approx. $0,000936$

Best Answer

Hint

By similarity with least square fit problems, I think that you need to minimize $$F=\int_0^{\pi}\Big(\sin(x)-(a x^2+bx+c)\Big)^2~dx$$ Compute the expression and say that $$\frac{dF}{da}=\frac{dF}{db}=\frac{dF}{dc}=0$$ This will provide three linear equations for the three unknowns $a,b,c$.

This seems to be very similar to what you posted (and the result is quite good).

Edited later

The answer you obtained is perfectly right but, if I may, I would like to add a comment about the problem itself. Fist, you notices that the function does not reproduce the values of $\sin(x)$ at the bounds.

As mentioned by Lucian, almost 1400 years ago, Mahabhaskariya of Bhaskara I, a seventh-century Indian mathematician and astronomer, proposed for the sine developements in terms of $x(\pi-x)$. So, let me consider the approximation $$\sin(x)\approx \sum_{i=1}^j a_i \big(x(\pi-x)\big)^i$$ (I excluded constant terms in order the values of $\sin(x)$ at the bounds be respected) and repeat the calculations as you made them (you could notice from your final result that the expression corresponds to $j=1$ plus a constant term).

For $j=1$, $F=2.27 \times 10^{-3}$ which is effectively worse than the $9.36 \times 10^{-4}$ you obtained (because I omitted the constant term).

For $j=2$, $F=7.89 \times 10^{-7}$ which is much better.

For $j=3$, $F=6.77 \times 10^{-10}$ which is much much better.

This was just to show that, depending on the base function we select, for the same number of adjustable parameters (or even less), we can make approximations of very different quality.

Just for your curiosity, the marvelous approximation given 1400 years ago $$\sin(x) \simeq \frac{16 (\pi -x) x}{5 \pi ^2-4 (\pi -x) x}$$ leads to $F=2.98 \times 10^{-6}$.

Related Question