Let $H = L^2([0, 1])$ and let $K \subset H$ be defined as $K = \{f \in H \, : \, \int_{[0,1]} f \, \mathrm{d}m = 0\}$. Show that $K$ is a closed vector subspace of $H$. Find the element of $K$ that is closest to $g(x) = x$ (note $g \in H \,\backslash \, K$).
(The integrals are Lebesgue integrals, in case that's not clear.)
This problem was on a problem set for $L^p$ spaces in my undergraduate-level real analysis course. Showing that $K$ is a vector subspace is easy; it is evident that the zero function is an element of $K$ and properties of Lebesgue integration give us that for functions $f,g \in K$, we have that $f+g \in K$, and also for a scalar $c \in \mathbb{R}$, we have $cf \in K$. This shows that $K$ is a vector subspace of $H$, but as my grader noted, that is insufficient to show that this is a closed vector subspace of $H$. Unless I'm overlooking something relatively obvious, I'm not sure what I'm missing there.
So onto the second part of the question: finding the element of $K$ that is closest to $g(x) = x$. Now, the projection of $g(x) = x$ onto $K$ will satisfy this condition, and to find that, we need to find $f$ such that $\langle g-f,f \rangle = 0$, where the angle brackets denote the usual inner product on the Hilbert space $L^2$, which is $\langle h,j \rangle = \int h \bar{j} \; \mathrm{d}m$, but since we're working in the reals, the complex conjugate is irrelevant. So since we are given $g$, we can expand $\langle g-f,f \rangle$: $$\langle g-f,f \rangle = \int (g-f) \bar{f} \mathrm{d}m = \int (g-f)f \, \mathrm{d}m = \int (x-f)f \, \mathrm{d}m = 0$$
So $f(x) \equiv 0$ or $f(x) = x$, but in the latter case, $f(x) = g(x) \not\in K$, so then $f(x) \equiv 0$. The grader says, however, that it is not true that $(x-f)f = 0$, and I guess I can see why (plenty of non-zero functions have zero integral on $[0,1]$, and this isn't even considering functions that are merely equal to zero a.e., so I feel pretty silly for making that mistake), but does that change my answer? After all, I only lost one point on this section and one point on the first section. What am I missing in each part of this question?
The function $u(x):=1$ $(0\leq x\leq1)$ is in $H$, and the map $$\phi:\quad H\to{\mathbb R}, \qquad f\mapsto \langle u,f\rangle$$ is continuous. Therefore $K={\rm ker\,}(\phi)$ is a closed subspace of $H$.
It is now "geometrically obvious" how we obtain the element $g\in K$ nearest to the function ${\rm id}: \>x\mapsto x$: Subtract from ${\rm id}$ a suitable multiple $\lambda u$, such that $g:={\rm id}-\lambda u\in K$. I'd say that $$g(x):=x-{1\over2}\qquad(0\leq x\leq1)$$ does the trick.