= Solution
For any $q\in\Pi_n$, write $f-q=(f-p)+(p-q)$. The stated <orthogonality> makes the two summands perpendicular in the given <inner product>, because $p-q\in\Pi_n$. The <Pythagorean theorem for inner product spaces> therefore gives
$$
\|f-q\|^2=\|f-p\|^2+\|p-q\|^2\geq\|f-p\|^2.
$$
Equality is attained at $q=p$, and positive definiteness makes it unique. Thus $p$ is the <orthogonal projection> of $f$ onto the <polynomial> subspace.
For the weighted example set $p(x)=A+Bx$. <Orthogonality> against the <basis> $1,x$ gives
$$
0=\int_{-1}^1x^2(x^2-A-Bx)\,dx=\frac25-\frac{2A}3,
$$
$$
0=\int_{-1}^1x^3(x^2-A-Bx)\,dx=-\frac{2B}5.
$$
Odd terms vanish on the symmetric <interval>, so $A=3/5$ and $B=0$. Consequently
$$
\boxed{p(x)=\frac35}.
$$
The weight $x^2$ vanishes only at one point; its integral against $g^2$ is positive for every nonzero <continuous> $g$, so it really does define an <inner product>. For an optional error check, the squared minimum error is $2/7-12/25+6/25=8/175$.
Back to article page