<s>[INST] cubic polynomial for $L^2$ approximation. 
Consider $f(x) = \sin \pi x$. Find the cubic polynomial giving $L^2$ approximation to $f$ on $[0,1]$.

I suspect I need to find a polynomial of the form $p(x) = \sum\limits_{i=0}^3 c_ix^i$ and calculate this (EDIT: below):
$$\int_0^1\left|f(x) - p(x)\right|^2 dx$$
(EDIT)Following along with this pdf.
I am using the standard monomial basis $\{x^i\}_{i=0}^n$ where $n=3$ in my case. Then I need to solve the Hilbert matrix below
$$
\left[\begin{matrix}
1 & \frac 12 & \frac 13 & \frac 14 \\
\frac 12 & \frac 13 & \frac 14 & \frac 15 \\
\frac 13 & \frac 14 & \frac 15 & \frac 16 \\
\frac 14 & \frac 15 & \frac 16 & \frac 17 
\end{matrix}\right]\left[\begin{matrix}
c_0 \\ c_1 \\ c_2 \\ c_3
\end{matrix}\right] = \left[\begin{matrix}
\int_0^1f(x) dx \\ 
\int_0^1f(x)x dx \\ 
\int_0^1f(x)x^2 dx \\
\int_0^1f(x) x^3 dx
\end{matrix}\right].
$$
We then get the following augmented matrix system to solve for the $c_i$'s:
$$
\left[\begin{matrix}
1 & \frac 12 & \frac 13 & \frac 14 & \frac 2\pi\\
\frac 12 & \frac 13 & \frac 14 & \frac 15 & \frac 1\pi\\
\frac 13 & \frac 14 & \frac 15 & \frac 16 & \frac 1\pi - \frac 4{\pi^3}\\
\frac 14 & \frac 15 & \frac 16 & \frac 17 & \frac 1\pi - \frac 6{\pi^3}
\end{matrix}\right] 
\sim 
\left[\begin{matrix}
1 & \frac 12 & \frac 13 & \frac 14 & \frac 2\pi\\
0 & \frac 1{12} & \frac 1{12} \frac 3{40} & 0 \\
0 & 0 & \frac1{120} & \frac 9{700} & \frac{\pi^2-12}{2\pi^2} \\
0 & 0 & 0 & \frac{-1}{4200} & 0
\end{matrix}\right].
$$
Which then gives use the following where constants as
$$
\begin{cases}
c_0 = \frac 2\pi + \frac k6 \\
c_1 = -k\\
c_2 = k \\
c_3 = 0 
\end{cases}
$$
where $k=\frac{\pi^2-12}{2\pi^2}120$.
Finally the cubic polynomial is
$$
p(x) = \left(\frac 2\pi + 120k\right) + (-kx) + kx^2 + 0. 
$$
Is this what the question is intending?
Btw, I am not sure what mathematical tag this falls under so help with categorizing this type of problem would be appreciated too!
 [/INST] The question is quite badly worded, in my opinion. I suppose it is asking you to find the cubic polynomial that is the best approximation of $f(x)$ in the $L2$ norm on the interval $[0,1]$.
In other words, you need to find the cubic polynomial $p$ that makes the error
$$
\int_0^1(f(x)-p(x))^2\,dx
$$
as small as possible.
</s>